1
0

put-dfanalytics.asciidoc 27 KB

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