put-dfanalytics.asciidoc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[put-dfanalytics]]
  4. = Create {dfanalytics-jobs} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Create {dfanalytics-jobs}</titleabbrev>
  8. ++++
  9. Instantiates a {dfanalytics-job}.
  10. [[ml-put-dfanalytics-request]]
  11. == {api-request-title}
  12. `PUT _ml/data_frame/analytics/<data_frame_analytics_id>`
  13. [[ml-put-dfanalytics-prereq]]
  14. == {api-prereq-title}
  15. Requires the following privileges:
  16. * cluster: `manage_ml` (the `machine_learning_admin` built-in role grants this
  17. privilege)
  18. * source indices: `read`, `view_index_metadata`
  19. * destination index: `read`, `create_index`, `manage` and `index`
  20. NOTE: The {dfanalytics-job} remembers which roles the user who created it had at
  21. the time of creation. When you start the job, it performs the analysis using
  22. those same roles. If you provide
  23. <<http-clients-secondary-authorization,secondary authorization headers>>,
  24. those credentials are used instead.
  25. [[ml-put-dfanalytics-desc]]
  26. == {api-description-title}
  27. This API creates a {dfanalytics-job} that performs an analysis on the source
  28. indices and stores the outcome in a destination index.
  29. If the destination index does not exist, it is created automatically when you
  30. start the job. See <<start-dfanalytics>>.
  31. If you supply only a subset of the {regression} or {classification} parameters,
  32. {ml-docs}/hyperparameters.html[hyperparameter optimization] occurs. It
  33. determines a value for each of the undefined parameters.
  34. [[ml-put-dfanalytics-path-params]]
  35. == {api-path-parms-title}
  36. `<data_frame_analytics_id>`::
  37. (Required, string)
  38. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-data-frame-analytics-define]
  39. [role="child_attributes"]
  40. [[ml-put-dfanalytics-request-body]]
  41. == {api-request-body-title}
  42. `allow_lazy_start`::
  43. (Optional, Boolean)
  44. Specifies whether this job can start when there is insufficient {ml} node
  45. capacity for it to be immediately assigned to a node. The default is `false`; if
  46. a {ml} node with capacity to run the job cannot immediately be found, the API
  47. returns an error. However, this is also subject to the cluster-wide
  48. `xpack.ml.max_lazy_ml_nodes` setting. See <<advanced-ml-settings>>. If this
  49. option is set to `true`, the API does not return an error and the job waits in
  50. the `starting` state until sufficient {ml} node capacity is available.
  51. //Begin analysis
  52. `analysis`::
  53. (Required, object)
  54. The analysis configuration, which contains the information necessary to perform
  55. one of the following types of analysis: {classification}, {oldetection}, or
  56. {regression}.
  57. +
  58. .Properties of `analysis`
  59. [%collapsible%open]
  60. ====
  61. //Begin classification
  62. `classification`:::
  63. (Required^*^, object)
  64. The configuration information necessary to perform
  65. {ml-docs}/ml-dfa-classification.html[{classification}].
  66. +
  67. TIP: Advanced parameters are for fine-tuning {classanalysis}. They are set
  68. automatically by hyperparameter optimization to give the minimum validation
  69. error. It is highly recommended to use the default values unless you fully
  70. understand the function of these parameters.
  71. +
  72. .Properties of `classification`
  73. [%collapsible%open]
  74. =====
  75. `alpha`::::
  76. (Optional, double)
  77. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-alpha]
  78. `class_assignment_objective`::::
  79. (Optional, string)
  80. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=class-assignment-objective]
  81. `dependent_variable`::::
  82. (Required, string)
  83. +
  84. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dependent-variable]
  85. +
  86. The data type of the field must be numeric (`integer`, `short`, `long`, `byte`),
  87. categorical (`ip` or `keyword`), or boolean. There must be no more than 30
  88. different values in this field.
  89. `downsample_factor`::::
  90. (Optional, double)
  91. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-downsample-factor]
  92. `early_stopping_enabled`::::
  93. (Optional, Boolean)
  94. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-early-stopping-enabled]
  95. `eta`::::
  96. (Optional, double)
  97. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=eta]
  98. `eta_growth_rate_per_tree`::::
  99. (Optional, double)
  100. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-eta-growth]
  101. `feature_bag_fraction`::::
  102. (Optional, double)
  103. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-bag-fraction]
  104. `feature_processors`::::
  105. (Optional, list)
  106. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors]
  107. +
  108. .Properties of `feature_processors`
  109. [%collapsible%open]
  110. ======
  111. `frequency_encoding`::::
  112. (object)
  113. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-frequency]
  114. +
  115. .Properties of `frequency_encoding`
  116. [%collapsible%open]
  117. =======
  118. `feature_name`::::
  119. (Required, string)
  120. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-feat-name]
  121. `field`::::
  122. (Required, string)
  123. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  124. `frequency_map`::::
  125. (Required, object)
  126. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-frequency-map]
  127. =======
  128. `multi_encoding`::::
  129. (object)
  130. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-multi]
  131. +
  132. .Properties of `multi_encoding`
  133. [%collapsible%open]
  134. =======
  135. `processors`::::
  136. (Required, array)
  137. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-multi-proc]
  138. =======
  139. `n_gram_encoding`::::
  140. (object)
  141. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram]
  142. +
  143. .Properties of `n_gram_encoding`
  144. [%collapsible%open]
  145. =======
  146. `feature_prefix`::::
  147. (Optional, string)
  148. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-feat-pref]
  149. `field`::::
  150. (Required, string)
  151. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-field]
  152. `length`::::
  153. (Optional, integer)
  154. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-length]
  155. `n_grams`::::
  156. (Required, array)
  157. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-ngrams]
  158. `start`::::
  159. (Optional, integer)
  160. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-start]
  161. =======
  162. `one_hot_encoding`::::
  163. (object)
  164. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-one-hot]
  165. +
  166. .Properties of `one_hot_encoding`
  167. [%collapsible%open]
  168. =======
  169. `field`::::
  170. (Required, string)
  171. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  172. `hot_map`::::
  173. (Required, string)
  174. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-one-hot-map]
  175. =======
  176. `target_mean_encoding`::::
  177. (object)
  178. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean]
  179. +
  180. .Properties of `target_mean_encoding`
  181. [%collapsible%open]
  182. =======
  183. `default_value`::::
  184. (Required, integer)
  185. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean-default]
  186. `feature_name`::::
  187. (Required, string)
  188. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-feat-name]
  189. `field`::::
  190. (Required, string)
  191. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  192. `target_map`::::
  193. (Required, object)
  194. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean-map]
  195. =======
  196. ======
  197. `gamma`::::
  198. (Optional, double)
  199. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=gamma]
  200. `lambda`::::
  201. (Optional, double)
  202. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=lambda]
  203. `max_optimization_rounds_per_hyperparameter`::::
  204. (Optional, integer)
  205. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-max-optimization-rounds]
  206. `max_trees`::::
  207. (Optional, integer)
  208. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees]
  209. `num_top_classes`::::
  210. (Optional, integer)
  211. Defines the number of categories for which the predicted probabilities are
  212. reported. It must be non-negative or -1. If it is -1 or greater than the total
  213. number of categories, probabilities are reported for all categories; if you have
  214. a large number of categories, there could be a significant effect on the size of your destination index. Defaults to 2.
  215. +
  216. --
  217. NOTE: To use the
  218. {ml-docs}/ml-dfa-classification.html#ml-dfanalytics-class-aucroc[AUC ROC]
  219. evaluation method, `num_top_classes` must be set to `-1` or a value greater than
  220. or equal to the total number of categories.
  221. --
  222. `num_top_feature_importance_values`::::
  223. (Optional, integer)
  224. Advanced configuration option. Specifies the maximum number of
  225. {ml-docs}/ml-feature-importance.html[{feat-imp}] values per document to return.
  226. By default, it is zero and no {feat-imp} calculation occurs.
  227. `prediction_field_name`::::
  228. (Optional, string)
  229. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=prediction-field-name]
  230. `randomize_seed`::::
  231. (Optional, long)
  232. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=randomize-seed]
  233. `soft_tree_depth_limit`::::
  234. (Optional, double)
  235. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-limit]
  236. `soft_tree_depth_tolerance`::::
  237. (Optional, double)
  238. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-tolerance]
  239. `training_percent`::::
  240. (Optional, integer)
  241. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=training-percent]
  242. //End classification
  243. =====
  244. //Begin outlier_detection
  245. `outlier_detection`:::
  246. (Required^*^, object)
  247. The configuration information necessary to perform
  248. {ml-docs}/ml-dfa-finding-outliers.html[{oldetection}]:
  249. +
  250. .Properties of `outlier_detection`
  251. [%collapsible%open]
  252. =====
  253. `compute_feature_influence`::::
  254. (Optional, Boolean)
  255. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=compute-feature-influence]
  256. `feature_influence_threshold`::::
  257. (Optional, double)
  258. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-influence-threshold]
  259. `method`::::
  260. (Optional, string)
  261. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=method]
  262. `n_neighbors`::::
  263. (Optional, integer)
  264. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=n-neighbors]
  265. `outlier_fraction`::::
  266. (Optional, double)
  267. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=outlier-fraction]
  268. `standardization_enabled`::::
  269. (Optional, Boolean)
  270. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=standardization-enabled]
  271. //End outlier_detection
  272. =====
  273. //Begin regression
  274. `regression`:::
  275. (Required^*^, object)
  276. The configuration information necessary to perform
  277. {ml-docs}/ml-dfa-regression.html[{regression}].
  278. +
  279. TIP: Advanced parameters are for fine-tuning {reganalysis}. They are set
  280. automatically by hyperparameter optimization to give the minimum validation
  281. error. It is highly recommended to use the default values unless you fully
  282. understand the function of these parameters.
  283. +
  284. .Properties of `regression`
  285. [%collapsible%open]
  286. =====
  287. `alpha`::::
  288. (Optional, double)
  289. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-alpha]
  290. `dependent_variable`::::
  291. (Required, string)
  292. +
  293. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dependent-variable]
  294. +
  295. The data type of the field must be numeric.
  296. `downsample_factor`::::
  297. (Optional, double)
  298. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-downsample-factor]
  299. `early_stopping_enabled`::::
  300. (Optional, Boolean)
  301. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-early-stopping-enabled]
  302. `eta`::::
  303. (Optional, double)
  304. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=eta]
  305. `eta_growth_rate_per_tree`::::
  306. (Optional, double)
  307. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-eta-growth]
  308. `feature_bag_fraction`::::
  309. (Optional, double)
  310. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-bag-fraction]
  311. `feature_processors`::::
  312. (Optional, list)
  313. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors]
  314. `gamma`::::
  315. (Optional, double)
  316. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=gamma]
  317. `lambda`::::
  318. (Optional, double)
  319. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=lambda]
  320. `loss_function`::::
  321. (Optional, string)
  322. The loss function used during {regression}. Available options are `mse` (mean
  323. squared error), `msle` (mean squared logarithmic error), `huber` (Pseudo-Huber
  324. loss). Defaults to `mse`.
  325. Refer to
  326. {ml-docs}/dfa-regression-lossfunction.html[Loss functions for {regression} analyses]
  327. to learn more.
  328. `loss_function_parameter`::::
  329. (Optional, double)
  330. A positive number that is used as a parameter to the `loss_function`.
  331. `max_optimization_rounds_per_hyperparameter`::::
  332. (Optional, integer)
  333. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-max-optimization-rounds]
  334. `max_trees`::::
  335. (Optional, integer)
  336. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees]
  337. `num_top_feature_importance_values`::::
  338. (Optional, integer)
  339. Advanced configuration option. Specifies the maximum number of
  340. {ml-docs}/ml-feature-importance.html[{feat-imp}] values per document to return.
  341. By default, it is zero and no {feat-imp} calculation occurs.
  342. `prediction_field_name`::::
  343. (Optional, string)
  344. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=prediction-field-name]
  345. `randomize_seed`::::
  346. (Optional, long)
  347. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=randomize-seed]
  348. `soft_tree_depth_limit`::::
  349. (Optional, double)
  350. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-limit]
  351. `soft_tree_depth_tolerance`::::
  352. (Optional, double)
  353. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-tolerance]
  354. `training_percent`::::
  355. (Optional, integer)
  356. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=training-percent]
  357. =====
  358. //End regression
  359. ====
  360. //End analysis
  361. //Begin analyzed_fields
  362. `analyzed_fields`::
  363. (Optional, object)
  364. Specify `includes` and/or `excludes` patterns to select which fields will be
  365. included in the analysis. The patterns specified in `excludes` are applied last,
  366. therefore `excludes` takes precedence. In other words, if the same field is
  367. specified in both `includes` and `excludes`, then the field will not be included
  368. in the analysis.
  369. +
  370. --
  371. [[dfa-supported-fields]]
  372. The supported fields for each type of analysis are as follows:
  373. * {oldetection-cap} requires numeric or boolean data to analyze. The algorithms
  374. don't support missing values therefore fields that have data types other than
  375. numeric or boolean are ignored. Documents where included fields contain missing
  376. values, null values, or an array are also ignored. Therefore the `dest` index
  377. may contain documents that don't have an {olscore}.
  378. * {regression-cap} supports fields that are numeric, `boolean`, `text`,
  379. `keyword`, and `ip`. It is also tolerant of missing values. Fields that are
  380. supported are included in the analysis, other fields are ignored. Documents
  381. where included fields contain an array with two or more values are also
  382. ignored. Documents in the `dest` index that don’t contain a results field are
  383. not included in the {reganalysis}.
  384. * {classification-cap} supports fields that are numeric, `boolean`, `text`,
  385. `keyword`, and `ip`. It is also tolerant of missing values. Fields that are
  386. supported are included in the analysis, other fields are ignored. Documents
  387. where included fields contain an array with two or more values are also ignored.
  388. Documents in the `dest` index that don’t contain a results field are not
  389. included in the {classanalysis}. {classanalysis-cap} can be improved by mapping
  390. ordinal variable values to a single number. For example, in case of age ranges,
  391. you can model the values as "0-14" = 0, "15-24" = 1, "25-34" = 2, and so on.
  392. If `analyzed_fields` is not set, only the relevant fields will be included. For
  393. example, all the numeric fields for {oldetection}. For more information about
  394. field selection, see <<explain-dfanalytics>>.
  395. --
  396. +
  397. .Properties of `analyzed_fields`
  398. [%collapsible%open]
  399. ====
  400. `excludes`:::
  401. (Optional, array)
  402. An array of strings that defines the fields that will be excluded from the
  403. analysis. You do not need to add fields with unsupported data types to
  404. `excludes`, these fields are excluded from the analysis automatically.
  405. `includes`:::
  406. (Optional, array)
  407. An array of strings that defines the fields that will be included in the
  408. analysis.
  409. //End analyzed_fields
  410. ====
  411. `description`::
  412. (Optional, string)
  413. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=description-dfa]
  414. `dest`::
  415. (Required, object)
  416. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dest]
  417. `max_num_threads`::
  418. (Optional, integer)
  419. The maximum number of threads to be used by the analysis.
  420. The default value is `1`. Using more threads may decrease the time
  421. necessary to complete the analysis at the cost of using more CPU.
  422. Note that the process may use additional threads for operational
  423. functionality other than the analysis itself.
  424. `model_memory_limit`::
  425. (Optional, string)
  426. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-memory-limit-dfa]
  427. `source`::
  428. (object)
  429. The configuration of how to source the analysis data. It requires an `index`.
  430. Optionally, `query`, `runtime_mappings`, and `_source` may be specified.
  431. +
  432. .Properties of `source`
  433. [%collapsible%open]
  434. ====
  435. `index`:::
  436. (Required, string or array) Index or indices on which to perform the analysis.
  437. It can be a single index or index pattern as well as an array of indices or
  438. patterns.
  439. +
  440. WARNING: If your source indices contain documents with the same IDs, only the
  441. document that is indexed last appears in the destination index.
  442. `query`:::
  443. (Optional, object) The {es} query domain-specific language (<<query-dsl,DSL>>).
  444. This value corresponds to the query object in an {es} search POST body. All the
  445. options that are supported by {es} can be used, as this object is passed
  446. verbatim to {es}. By default, this property has the following value:
  447. `{"match_all": {}}`.
  448. `runtime_mappings`:::
  449. (Optional, object) Definitions of runtime fields that will become part of the
  450. mapping of the destination index.
  451. `_source`:::
  452. (Optional, object) Specify `includes` and/or `excludes` patterns to select which
  453. fields will be present in the destination. Fields that are excluded cannot be
  454. included in the analysis.
  455. +
  456. .Properties of `_source`
  457. [%collapsible%open]
  458. =====
  459. `includes`::::
  460. (array) An array of strings that defines the fields that will be included in the
  461. destination.
  462. `excludes`::::
  463. (array) An array of strings that defines the fields that will be excluded from
  464. the destination.
  465. =====
  466. ====
  467. [[ml-put-dfanalytics-example]]
  468. == {api-examples-title}
  469. [[ml-put-dfanalytics-example-preprocess]]
  470. === Preprocessing actions example
  471. The following example shows how to limit the scope of the analysis to certain
  472. fields, specify excluded fields in the destination index, and use a query to
  473. filter your data before analysis.
  474. [source,console]
  475. --------------------------------------------------
  476. PUT _ml/data_frame/analytics/model-flight-delays-pre
  477. {
  478. "source": {
  479. "index": [
  480. "kibana_sample_data_flights" <1>
  481. ],
  482. "query": { <2>
  483. "range": {
  484. "DistanceKilometers": {
  485. "gt": 0
  486. }
  487. }
  488. },
  489. "_source": { <3>
  490. "includes": [],
  491. "excludes": [
  492. "FlightDelay",
  493. "FlightDelayType"
  494. ]
  495. }
  496. },
  497. "dest": { <4>
  498. "index": "df-flight-delays",
  499. "results_field": "ml-results"
  500. },
  501. "analysis": {
  502. "regression": {
  503. "dependent_variable": "FlightDelayMin",
  504. "training_percent": 90
  505. }
  506. },
  507. "analyzed_fields": { <5>
  508. "includes": [],
  509. "excludes": [
  510. "FlightNum"
  511. ]
  512. },
  513. "model_memory_limit": "100mb"
  514. }
  515. --------------------------------------------------
  516. // TEST[skip:setup kibana sample data]
  517. <1> Source index to analyze.
  518. <2> This query filters out entire documents that will not be present in the
  519. destination index.
  520. <3> The `_source` object defines fields in the data set that will be included or
  521. excluded in the destination index.
  522. <4> Defines the destination index that contains the results of the analysis and
  523. the fields of the source index specified in the `_source` object. Also defines
  524. the name of the `results_field`.
  525. <5> Specifies fields to be included in or excluded from the analysis. This does
  526. not affect whether the fields will be present in the destination index, only
  527. affects whether they are used in the analysis.
  528. In this example, we can see that all the fields of the source index are included
  529. in the destination index except `FlightDelay` and `FlightDelayType` because
  530. these are defined as excluded fields by the `excludes` parameter of the
  531. `_source` object. The `FlightNum` field is included in the destination index,
  532. however it is not included in the analysis because it is explicitly specified as
  533. excluded field by the `excludes` parameter of the `analyzed_fields` object.
  534. [[ml-put-dfanalytics-example-od]]
  535. === {oldetection-cap} example
  536. The following example creates the `loganalytics` {dfanalytics-job}, the analysis
  537. type is `outlier_detection`:
  538. [source,console]
  539. --------------------------------------------------
  540. PUT _ml/data_frame/analytics/loganalytics
  541. {
  542. "description": "Outlier detection on log data",
  543. "source": {
  544. "index": "logdata"
  545. },
  546. "dest": {
  547. "index": "logdata_out"
  548. },
  549. "analysis": {
  550. "outlier_detection": {
  551. "compute_feature_influence": true,
  552. "outlier_fraction": 0.05,
  553. "standardization_enabled": true
  554. }
  555. }
  556. }
  557. --------------------------------------------------
  558. // TEST[setup:setup_logdata]
  559. The API returns the following result:
  560. [source,console-result]
  561. ----
  562. {
  563. "id": "loganalytics",
  564. "description": "Outlier detection on log data",
  565. "source": {
  566. "index": [ "logdata" ],
  567. "query": {
  568. "match_all": {}
  569. }
  570. },
  571. "dest": {
  572. "index": "logdata_out",
  573. "results_field": "ml"
  574. },
  575. "analysis": {
  576. "outlier_detection": {
  577. "compute_feature_influence": true,
  578. "outlier_fraction": 0.05,
  579. "standardization_enabled": true
  580. }
  581. },
  582. "model_memory_limit": "1gb",
  583. "create_time": 1562265491319,
  584. "version": "8.0.0",
  585. "allow_lazy_start": false,
  586. "max_num_threads": 1
  587. }
  588. ----
  589. // TESTRESPONSE[s/1562265491319/$body.$_path/]
  590. // TESTRESPONSE[s/"version" : "8.0.0"/"version" : $body.version/]
  591. [[ml-put-dfanalytics-example-r]]
  592. === {regression-cap} examples
  593. The following example creates the `house_price_regression_analysis`
  594. {dfanalytics-job}, the analysis type is `regression`:
  595. [source,console]
  596. --------------------------------------------------
  597. PUT _ml/data_frame/analytics/house_price_regression_analysis
  598. {
  599. "source": {
  600. "index": "houses_sold_last_10_yrs"
  601. },
  602. "dest": {
  603. "index": "house_price_predictions"
  604. },
  605. "analysis":
  606. {
  607. "regression": {
  608. "dependent_variable": "price"
  609. }
  610. }
  611. }
  612. --------------------------------------------------
  613. // TEST[skip:TBD]
  614. The API returns the following result:
  615. [source,console-result]
  616. ----
  617. {
  618. "id" : "house_price_regression_analysis",
  619. "source" : {
  620. "index" : [
  621. "houses_sold_last_10_yrs"
  622. ],
  623. "query" : {
  624. "match_all" : { }
  625. }
  626. },
  627. "dest" : {
  628. "index" : "house_price_predictions",
  629. "results_field" : "ml"
  630. },
  631. "analysis" : {
  632. "regression" : {
  633. "dependent_variable" : "price",
  634. "training_percent" : 100
  635. }
  636. },
  637. "model_memory_limit" : "1gb",
  638. "create_time" : 1567168659127,
  639. "version" : "8.0.0",
  640. "allow_lazy_start" : false
  641. }
  642. ----
  643. // TESTRESPONSE[s/1567168659127/$body.$_path/]
  644. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  645. The following example creates a job and specifies a training percent:
  646. [source,console]
  647. --------------------------------------------------
  648. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  649. {
  650. "source": {
  651. "index": "student_performance_mathematics"
  652. },
  653. "dest": {
  654. "index":"student_performance_mathematics_reg"
  655. },
  656. "analysis":
  657. {
  658. "regression": {
  659. "dependent_variable": "G3",
  660. "training_percent": 70, <1>
  661. "randomize_seed": 19673948271 <2>
  662. }
  663. }
  664. }
  665. --------------------------------------------------
  666. // TEST[skip:TBD]
  667. <1> The percentage of the data set that is used for training the model.
  668. <2> The seed that is used to randomly pick which data is used for training.
  669. The following example uses custom feature processors to transform the
  670. categorical values for `DestWeather` into numerical values using one-hot,
  671. target-mean, and frequency encoding techniques:
  672. [source,console]
  673. --------------------------------------------------
  674. PUT _ml/data_frame/analytics/flight_prices
  675. {
  676. "source": {
  677. "index": [
  678. "kibana_sample_data_flights"
  679. ]
  680. },
  681. "dest": {
  682. "index": "kibana_sample_flight_prices"
  683. },
  684. "analysis": {
  685. "regression": {
  686. "dependent_variable": "AvgTicketPrice",
  687. "num_top_feature_importance_values": 2,
  688. "feature_processors": [
  689. {
  690. "frequency_encoding": {
  691. "field": "DestWeather",
  692. "feature_name": "DestWeather_frequency",
  693. "frequency_map": {
  694. "Rain": 0.14604811155570188,
  695. "Heavy Fog": 0.14604811155570188,
  696. "Thunder & Lightning": 0.14604811155570188,
  697. "Cloudy": 0.14604811155570188,
  698. "Damaging Wind": 0.14604811155570188,
  699. "Hail": 0.14604811155570188,
  700. "Sunny": 0.14604811155570188,
  701. "Clear": 0.14604811155570188
  702. }
  703. }
  704. },
  705. {
  706. "target_mean_encoding": {
  707. "field": "DestWeather",
  708. "feature_name": "DestWeather_targetmean",
  709. "target_map": {
  710. "Rain": 626.5588814585794,
  711. "Heavy Fog": 626.5588814585794,
  712. "Thunder & Lightning": 626.5588814585794,
  713. "Hail": 626.5588814585794,
  714. "Damaging Wind": 626.5588814585794,
  715. "Cloudy": 626.5588814585794,
  716. "Clear": 626.5588814585794,
  717. "Sunny": 626.5588814585794
  718. },
  719. "default_value": 624.0249512020454
  720. }
  721. },
  722. {
  723. "one_hot_encoding": {
  724. "field": "DestWeather",
  725. "hot_map": {
  726. "Rain": "DestWeather_Rain",
  727. "Heavy Fog": "DestWeather_Heavy Fog",
  728. "Thunder & Lightning": "DestWeather_Thunder & Lightning",
  729. "Cloudy": "DestWeather_Cloudy",
  730. "Damaging Wind": "DestWeather_Damaging Wind",
  731. "Hail": "DestWeather_Hail",
  732. "Clear": "DestWeather_Clear",
  733. "Sunny": "DestWeather_Sunny"
  734. }
  735. }
  736. }
  737. ]
  738. }
  739. },
  740. "analyzed_fields": {
  741. "includes": [
  742. "AvgTicketPrice",
  743. "Cancelled",
  744. "DestWeather",
  745. "FlightDelayMin",
  746. "DistanceMiles"
  747. ]
  748. },
  749. "model_memory_limit": "30mb"
  750. }
  751. --------------------------------------------------
  752. // TEST[skip:TBD]
  753. NOTE: These custom feature processors are optional; automatic
  754. {ml-docs}/ml-feature-encoding.html[feature encoding] still occurs for all
  755. categorical features.
  756. [[ml-put-dfanalytics-example-c]]
  757. === {classification-cap} example
  758. The following example creates the `loan_classification` {dfanalytics-job}, the
  759. analysis type is `classification`:
  760. [source,console]
  761. --------------------------------------------------
  762. PUT _ml/data_frame/analytics/loan_classification
  763. {
  764. "source" : {
  765. "index": "loan-applicants"
  766. },
  767. "dest" : {
  768. "index": "loan-applicants-classified"
  769. },
  770. "analysis" : {
  771. "classification": {
  772. "dependent_variable": "label",
  773. "training_percent": 75,
  774. "num_top_classes": 2
  775. }
  776. }
  777. }
  778. --------------------------------------------------
  779. // TEST[skip:TBD]