put-dfanalytics.asciidoc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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}/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-dfanalytics-evaluate.html#ml-dfanalytics-class-aucroc[AUC ROC evaluation method],
  219. `num_top_classes` must be set to `-1` or a value greater than or equal to the
  220. 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 {oldetection}:
  248. // {ml-docs}/ml-dfa-finding-outliers.html#dfa-outlier-detection[{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}/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`. Refer to
  325. {ml-docs}/dfa-regression.html#dfa-regression-lossfunction[Loss functions for {regression} analyses]
  326. to learn more.
  327. `loss_function_parameter`::::
  328. (Optional, double)
  329. A positive number that is used as a parameter to the `loss_function`.
  330. `max_optimization_rounds_per_hyperparameter`::::
  331. (Optional, integer)
  332. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-max-optimization-rounds]
  333. `max_trees`::::
  334. (Optional, integer)
  335. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees]
  336. `num_top_feature_importance_values`::::
  337. (Optional, integer)
  338. Advanced configuration option. Specifies the maximum number of
  339. {ml-docs}/ml-feature-importance.html[{feat-imp}] values per document to return.
  340. By default, it is zero and no {feat-imp} calculation occurs.
  341. `prediction_field_name`::::
  342. (Optional, string)
  343. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=prediction-field-name]
  344. `randomize_seed`::::
  345. (Optional, long)
  346. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=randomize-seed]
  347. `soft_tree_depth_limit`::::
  348. (Optional, double)
  349. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-limit]
  350. `soft_tree_depth_tolerance`::::
  351. (Optional, double)
  352. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-tolerance]
  353. `training_percent`::::
  354. (Optional, integer)
  355. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=training-percent]
  356. =====
  357. //End regression
  358. ====
  359. //End analysis
  360. //Begin analyzed_fields
  361. `analyzed_fields`::
  362. (Optional, object)
  363. Specify `includes` and/or `excludes` patterns to select which fields will be
  364. included in the analysis. The patterns specified in `excludes` are applied last,
  365. therefore `excludes` takes precedence. In other words, if the same field is
  366. specified in both `includes` and `excludes`, then the field will not be included
  367. in the analysis.
  368. +
  369. --
  370. [[dfa-supported-fields]]
  371. The supported fields for each type of analysis are as follows:
  372. * {oldetection-cap} requires numeric or boolean data to analyze. The algorithms
  373. don't support missing values therefore fields that have data types other than
  374. numeric or boolean are ignored. Documents where included fields contain missing
  375. values, null values, or an array are also ignored. Therefore the `dest` index
  376. may contain documents that don't have an {olscore}.
  377. * {regression-cap} supports fields that are numeric, `boolean`, `text`,
  378. `keyword`, and `ip`. It is also tolerant of missing values. Fields that are
  379. supported are included in the analysis, other fields are ignored. Documents
  380. where included fields contain an array with two or more values are also
  381. ignored. Documents in the `dest` index that don’t contain a results field are
  382. not included in the {reganalysis}.
  383. * {classification-cap} supports fields that are numeric, `boolean`, `text`,
  384. `keyword`, and `ip`. It is also tolerant of missing values. Fields that are
  385. supported are included in the analysis, other fields are ignored. Documents
  386. where included fields contain an array with two or more values are also ignored.
  387. Documents in the `dest` index that don’t contain a results field are not
  388. included in the {classanalysis}. {classanalysis-cap} can be improved by mapping
  389. ordinal variable values to a single number. For example, in case of age ranges,
  390. you can model the values as "0-14" = 0, "15-24" = 1, "25-34" = 2, and so on.
  391. If `analyzed_fields` is not set, only the relevant fields will be included. For
  392. example, all the numeric fields for {oldetection}. For more information about
  393. field selection, see <<explain-dfanalytics>>.
  394. --
  395. +
  396. .Properties of `analyzed_fields`
  397. [%collapsible%open]
  398. ====
  399. `excludes`:::
  400. (Optional, array)
  401. An array of strings that defines the fields that will be excluded from the
  402. analysis. You do not need to add fields with unsupported data types to
  403. `excludes`, these fields are excluded from the analysis automatically.
  404. `includes`:::
  405. (Optional, array)
  406. An array of strings that defines the fields that will be included in the
  407. analysis.
  408. //End analyzed_fields
  409. ====
  410. `description`::
  411. (Optional, string)
  412. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=description-dfa]
  413. `dest`::
  414. (Required, object)
  415. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dest]
  416. `max_num_threads`::
  417. (Optional, integer)
  418. The maximum number of threads to be used by the analysis.
  419. The default value is `1`. Using more threads may decrease the time
  420. necessary to complete the analysis at the cost of using more CPU.
  421. Note that the process may use additional threads for operational
  422. functionality other than the analysis itself.
  423. `model_memory_limit`::
  424. (Optional, string)
  425. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-memory-limit-dfa]
  426. `source`::
  427. (object)
  428. The configuration of how to source the analysis data. It requires an `index`.
  429. Optionally, `query`, `runtime_mappings`, and `_source` may be specified.
  430. +
  431. .Properties of `source`
  432. [%collapsible%open]
  433. ====
  434. `index`:::
  435. (Required, string or array) Index or indices on which to perform the analysis.
  436. It can be a single index or index pattern as well as an array of indices or
  437. patterns.
  438. +
  439. WARNING: If your source indices contain documents with the same IDs, only the
  440. document that is indexed last appears in the destination index.
  441. `query`:::
  442. (Optional, object) The {es} query domain-specific language (<<query-dsl,DSL>>).
  443. This value corresponds to the query object in an {es} search POST body. All the
  444. options that are supported by {es} can be used, as this object is passed
  445. verbatim to {es}. By default, this property has the following value:
  446. `{"match_all": {}}`.
  447. `runtime_mappings`:::
  448. (Optional, object) Definitions of runtime fields that will become part of the
  449. mapping of the destination index.
  450. `_source`:::
  451. (Optional, object) Specify `includes` and/or `excludes` patterns to select which
  452. fields will be present in the destination. Fields that are excluded cannot be
  453. included in the analysis.
  454. +
  455. .Properties of `_source`
  456. [%collapsible%open]
  457. =====
  458. `includes`::::
  459. (array) An array of strings that defines the fields that will be included in the
  460. destination.
  461. `excludes`::::
  462. (array) An array of strings that defines the fields that will be excluded from
  463. the destination.
  464. =====
  465. ====
  466. [[ml-put-dfanalytics-example]]
  467. == {api-examples-title}
  468. [[ml-put-dfanalytics-example-preprocess]]
  469. === Preprocessing actions example
  470. The following example shows how to limit the scope of the analysis to certain
  471. fields, specify excluded fields in the destination index, and use a query to
  472. filter your data before analysis.
  473. [source,console]
  474. --------------------------------------------------
  475. PUT _ml/data_frame/analytics/model-flight-delays-pre
  476. {
  477. "source": {
  478. "index": [
  479. "kibana_sample_data_flights" <1>
  480. ],
  481. "query": { <2>
  482. "range": {
  483. "DistanceKilometers": {
  484. "gt": 0
  485. }
  486. }
  487. },
  488. "_source": { <3>
  489. "includes": [],
  490. "excludes": [
  491. "FlightDelay",
  492. "FlightDelayType"
  493. ]
  494. }
  495. },
  496. "dest": { <4>
  497. "index": "df-flight-delays",
  498. "results_field": "ml-results"
  499. },
  500. "analysis": {
  501. "regression": {
  502. "dependent_variable": "FlightDelayMin",
  503. "training_percent": 90
  504. }
  505. },
  506. "analyzed_fields": { <5>
  507. "includes": [],
  508. "excludes": [
  509. "FlightNum"
  510. ]
  511. },
  512. "model_memory_limit": "100mb"
  513. }
  514. --------------------------------------------------
  515. // TEST[skip:setup kibana sample data]
  516. <1> Source index to analyze.
  517. <2> This query filters out entire documents that will not be present in the
  518. destination index.
  519. <3> The `_source` object defines fields in the data set that will be included or
  520. excluded in the destination index.
  521. <4> Defines the destination index that contains the results of the analysis and
  522. the fields of the source index specified in the `_source` object. Also defines
  523. the name of the `results_field`.
  524. <5> Specifies fields to be included in or excluded from the analysis. This does
  525. not affect whether the fields will be present in the destination index, only
  526. affects whether they are used in the analysis.
  527. In this example, we can see that all the fields of the source index are included
  528. in the destination index except `FlightDelay` and `FlightDelayType` because
  529. these are defined as excluded fields by the `excludes` parameter of the
  530. `_source` object. The `FlightNum` field is included in the destination index,
  531. however it is not included in the analysis because it is explicitly specified as
  532. excluded field by the `excludes` parameter of the `analyzed_fields` object.
  533. [[ml-put-dfanalytics-example-od]]
  534. === {oldetection-cap} example
  535. The following example creates the `loganalytics` {dfanalytics-job}, the analysis
  536. type is `outlier_detection`:
  537. [source,console]
  538. --------------------------------------------------
  539. PUT _ml/data_frame/analytics/loganalytics
  540. {
  541. "description": "Outlier detection on log data",
  542. "source": {
  543. "index": "logdata"
  544. },
  545. "dest": {
  546. "index": "logdata_out"
  547. },
  548. "analysis": {
  549. "outlier_detection": {
  550. "compute_feature_influence": true,
  551. "outlier_fraction": 0.05,
  552. "standardization_enabled": true
  553. }
  554. }
  555. }
  556. --------------------------------------------------
  557. // TEST[setup:setup_logdata]
  558. The API returns the following result:
  559. [source,console-result]
  560. ----
  561. {
  562. "id": "loganalytics",
  563. "description": "Outlier detection on log data",
  564. "source": {
  565. "index": [ "logdata" ],
  566. "query": {
  567. "match_all": {}
  568. }
  569. },
  570. "dest": {
  571. "index": "logdata_out",
  572. "results_field": "ml"
  573. },
  574. "analysis": {
  575. "outlier_detection": {
  576. "compute_feature_influence": true,
  577. "outlier_fraction": 0.05,
  578. "standardization_enabled": true
  579. }
  580. },
  581. "model_memory_limit": "1gb",
  582. "create_time": 1562265491319,
  583. "version": "8.0.0",
  584. "allow_lazy_start": false,
  585. "max_num_threads": 1
  586. }
  587. ----
  588. // TESTRESPONSE[s/1562265491319/$body.$_path/]
  589. // TESTRESPONSE[s/"version" : "8.0.0"/"version" : $body.version/]
  590. [[ml-put-dfanalytics-example-r]]
  591. === {regression-cap} examples
  592. The following example creates the `house_price_regression_analysis`
  593. {dfanalytics-job}, the analysis type is `regression`:
  594. [source,console]
  595. --------------------------------------------------
  596. PUT _ml/data_frame/analytics/house_price_regression_analysis
  597. {
  598. "source": {
  599. "index": "houses_sold_last_10_yrs"
  600. },
  601. "dest": {
  602. "index": "house_price_predictions"
  603. },
  604. "analysis":
  605. {
  606. "regression": {
  607. "dependent_variable": "price"
  608. }
  609. }
  610. }
  611. --------------------------------------------------
  612. // TEST[skip:TBD]
  613. The API returns the following result:
  614. [source,console-result]
  615. ----
  616. {
  617. "id" : "house_price_regression_analysis",
  618. "source" : {
  619. "index" : [
  620. "houses_sold_last_10_yrs"
  621. ],
  622. "query" : {
  623. "match_all" : { }
  624. }
  625. },
  626. "dest" : {
  627. "index" : "house_price_predictions",
  628. "results_field" : "ml"
  629. },
  630. "analysis" : {
  631. "regression" : {
  632. "dependent_variable" : "price",
  633. "training_percent" : 100
  634. }
  635. },
  636. "model_memory_limit" : "1gb",
  637. "create_time" : 1567168659127,
  638. "version" : "8.0.0",
  639. "allow_lazy_start" : false
  640. }
  641. ----
  642. // TESTRESPONSE[s/1567168659127/$body.$_path/]
  643. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  644. The following example creates a job and specifies a training percent:
  645. [source,console]
  646. --------------------------------------------------
  647. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  648. {
  649. "source": {
  650. "index": "student_performance_mathematics"
  651. },
  652. "dest": {
  653. "index":"student_performance_mathematics_reg"
  654. },
  655. "analysis":
  656. {
  657. "regression": {
  658. "dependent_variable": "G3",
  659. "training_percent": 70, <1>
  660. "randomize_seed": 19673948271 <2>
  661. }
  662. }
  663. }
  664. --------------------------------------------------
  665. // TEST[skip:TBD]
  666. <1> The percentage of the data set that is used for training the model.
  667. <2> The seed that is used to randomly pick which data is used for training.
  668. The following example uses custom feature processors to transform the
  669. categorical values for `DestWeather` into numerical values using one-hot,
  670. target-mean, and frequency encoding techniques:
  671. [source,console]
  672. --------------------------------------------------
  673. PUT _ml/data_frame/analytics/flight_prices
  674. {
  675. "source": {
  676. "index": [
  677. "kibana_sample_data_flights"
  678. ]
  679. },
  680. "dest": {
  681. "index": "kibana_sample_flight_prices"
  682. },
  683. "analysis": {
  684. "regression": {
  685. "dependent_variable": "AvgTicketPrice",
  686. "num_top_feature_importance_values": 2,
  687. "feature_processors": [
  688. {
  689. "frequency_encoding": {
  690. "field": "DestWeather",
  691. "feature_name": "DestWeather_frequency",
  692. "frequency_map": {
  693. "Rain": 0.14604811155570188,
  694. "Heavy Fog": 0.14604811155570188,
  695. "Thunder & Lightning": 0.14604811155570188,
  696. "Cloudy": 0.14604811155570188,
  697. "Damaging Wind": 0.14604811155570188,
  698. "Hail": 0.14604811155570188,
  699. "Sunny": 0.14604811155570188,
  700. "Clear": 0.14604811155570188
  701. }
  702. }
  703. },
  704. {
  705. "target_mean_encoding": {
  706. "field": "DestWeather",
  707. "feature_name": "DestWeather_targetmean",
  708. "target_map": {
  709. "Rain": 626.5588814585794,
  710. "Heavy Fog": 626.5588814585794,
  711. "Thunder & Lightning": 626.5588814585794,
  712. "Hail": 626.5588814585794,
  713. "Damaging Wind": 626.5588814585794,
  714. "Cloudy": 626.5588814585794,
  715. "Clear": 626.5588814585794,
  716. "Sunny": 626.5588814585794
  717. },
  718. "default_value": 624.0249512020454
  719. }
  720. },
  721. {
  722. "one_hot_encoding": {
  723. "field": "DestWeather",
  724. "hot_map": {
  725. "Rain": "DestWeather_Rain",
  726. "Heavy Fog": "DestWeather_Heavy Fog",
  727. "Thunder & Lightning": "DestWeather_Thunder & Lightning",
  728. "Cloudy": "DestWeather_Cloudy",
  729. "Damaging Wind": "DestWeather_Damaging Wind",
  730. "Hail": "DestWeather_Hail",
  731. "Clear": "DestWeather_Clear",
  732. "Sunny": "DestWeather_Sunny"
  733. }
  734. }
  735. }
  736. ]
  737. }
  738. },
  739. "analyzed_fields": {
  740. "includes": [
  741. "AvgTicketPrice",
  742. "Cancelled",
  743. "DestWeather",
  744. "FlightDelayMin",
  745. "DistanceMiles"
  746. ]
  747. },
  748. "model_memory_limit": "30mb"
  749. }
  750. --------------------------------------------------
  751. // TEST[skip:TBD]
  752. NOTE: These custom feature processors are optional; automatic
  753. {ml-docs}/ml-feature-encoding.html[feature encoding] still occurs for all
  754. categorical features.
  755. [[ml-put-dfanalytics-example-c]]
  756. === {classification-cap} example
  757. The following example creates the `loan_classification` {dfanalytics-job}, the
  758. analysis type is `classification`:
  759. [source,console]
  760. --------------------------------------------------
  761. PUT _ml/data_frame/analytics/loan_classification
  762. {
  763. "source" : {
  764. "index": "loan-applicants"
  765. },
  766. "dest" : {
  767. "index": "loan-applicants-classified"
  768. },
  769. "analysis" : {
  770. "classification": {
  771. "dependent_variable": "label",
  772. "training_percent": 75,
  773. "num_top_classes": 2
  774. }
  775. }
  776. }
  777. --------------------------------------------------
  778. // TEST[skip:TBD]