put-dfanalytics.asciidoc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. [role="xpack"]
  2. [[put-dfanalytics]]
  3. = Create {dfanalytics-jobs} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Create {dfanalytics-jobs}</titleabbrev>
  7. ++++
  8. Instantiates a {dfanalytics-job}.
  9. [[ml-put-dfanalytics-request]]
  10. == {api-request-title}
  11. `PUT _ml/data_frame/analytics/<data_frame_analytics_id>`
  12. [[ml-put-dfanalytics-prereq]]
  13. == {api-prereq-title}
  14. Requires the following privileges:
  15. * cluster: `manage_ml` (the `machine_learning_admin` built-in role grants this
  16. privilege)
  17. * source indices: `read`, `view_index_metadata`
  18. * destination index: `read`, `create_index`, `manage` and `index`
  19. NOTE: The {dfanalytics-job} remembers which roles the user who created it had at
  20. the time of creation. When you start the job, it performs the analysis using
  21. those same roles. If you provide
  22. <<http-clients-secondary-authorization,secondary authorization headers>>,
  23. those credentials are used instead.
  24. [[ml-put-dfanalytics-desc]]
  25. == {api-description-title}
  26. This API creates a {dfanalytics-job} that performs an analysis on the source
  27. indices and stores the outcome in a destination index.
  28. If the destination index does not exist, it is created automatically when you
  29. start the job. See <<start-dfanalytics>>.
  30. If you supply only a subset of the {regression} or {classification} parameters,
  31. {ml-docs}/hyperparameters.html[hyperparameter optimization] occurs. It
  32. determines a value for each of the undefined parameters.
  33. [[ml-put-dfanalytics-path-params]]
  34. == {api-path-parms-title}
  35. `<data_frame_analytics_id>`::
  36. (Required, string)
  37. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-data-frame-analytics-define]
  38. [role="child_attributes"]
  39. [[ml-put-dfanalytics-request-body]]
  40. == {api-request-body-title}
  41. `allow_lazy_start`::
  42. (Optional, Boolean)
  43. Specifies whether this job can start when there is insufficient {ml} node
  44. capacity for it to be immediately assigned to a node. The default is `false`; if
  45. a {ml} node with capacity to run the job cannot immediately be found, the API
  46. returns an error. However, this is also subject to the cluster-wide
  47. `xpack.ml.max_lazy_ml_nodes` setting. See <<advanced-ml-settings>>. If this
  48. option is set to `true`, the API does not return an error and the job waits in
  49. the `starting` state until sufficient {ml} node capacity is available.
  50. //Begin analysis
  51. `analysis`::
  52. (Required, object)
  53. The analysis configuration, which contains the information necessary to perform
  54. one of the following types of analysis: {classification}, {oldetection}, or
  55. {regression}.
  56. +
  57. .Properties of `analysis`
  58. [%collapsible%open]
  59. ====
  60. //Begin classification
  61. `classification`:::
  62. (Required^*^, object)
  63. The configuration information necessary to perform
  64. {ml-docs}/ml-dfa-classification.html[{classification}].
  65. +
  66. TIP: Advanced parameters are for fine-tuning {classanalysis}. They are set
  67. automatically by hyperparameter optimization to give the minimum validation
  68. error. It is highly recommended to use the default values unless you fully
  69. understand the function of these parameters.
  70. +
  71. .Properties of `classification`
  72. [%collapsible%open]
  73. =====
  74. `alpha`::::
  75. (Optional, double)
  76. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-alpha]
  77. `class_assignment_objective`::::
  78. (Optional, string)
  79. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=class-assignment-objective]
  80. `dependent_variable`::::
  81. (Required, string)
  82. +
  83. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dependent-variable]
  84. +
  85. The data type of the field must be numeric (`integer`, `short`, `long`, `byte`),
  86. categorical (`ip` or `keyword`), or boolean. There must be no more than 30
  87. different values in this field.
  88. `downsample_factor`::::
  89. (Optional, double)
  90. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-downsample-factor]
  91. `early_stopping_enabled`::::
  92. (Optional, Boolean)
  93. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-early-stopping-enabled]
  94. `eta`::::
  95. (Optional, double)
  96. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=eta]
  97. `eta_growth_rate_per_tree`::::
  98. (Optional, double)
  99. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-eta-growth]
  100. `feature_bag_fraction`::::
  101. (Optional, double)
  102. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-bag-fraction]
  103. `feature_processors`::::
  104. (Optional, list)
  105. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors]
  106. +
  107. .Properties of `feature_processors`
  108. [%collapsible%open]
  109. ======
  110. `frequency_encoding`::::
  111. (object)
  112. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-frequency]
  113. +
  114. .Properties of `frequency_encoding`
  115. [%collapsible%open]
  116. =======
  117. `feature_name`::::
  118. (Required, string)
  119. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-feat-name]
  120. `field`::::
  121. (Required, string)
  122. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  123. `frequency_map`::::
  124. (Required, object)
  125. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-frequency-map]
  126. =======
  127. `multi_encoding`::::
  128. (object)
  129. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-multi]
  130. +
  131. .Properties of `multi_encoding`
  132. [%collapsible%open]
  133. =======
  134. `processors`::::
  135. (Required, array)
  136. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-multi-proc]
  137. =======
  138. `n_gram_encoding`::::
  139. (object)
  140. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram]
  141. +
  142. .Properties of `n_gram_encoding`
  143. [%collapsible%open]
  144. =======
  145. `feature_prefix`::::
  146. (Optional, string)
  147. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-feat-pref]
  148. `field`::::
  149. (Required, string)
  150. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-field]
  151. `length`::::
  152. (Optional, integer)
  153. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-length]
  154. `n_grams`::::
  155. (Required, array)
  156. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-ngrams]
  157. `start`::::
  158. (Optional, integer)
  159. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-ngram-start]
  160. =======
  161. `one_hot_encoding`::::
  162. (object)
  163. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-one-hot]
  164. +
  165. .Properties of `one_hot_encoding`
  166. [%collapsible%open]
  167. =======
  168. `field`::::
  169. (Required, string)
  170. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  171. `hot_map`::::
  172. (Required, string)
  173. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-one-hot-map]
  174. =======
  175. `target_mean_encoding`::::
  176. (object)
  177. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean]
  178. +
  179. .Properties of `target_mean_encoding`
  180. [%collapsible%open]
  181. =======
  182. `default_value`::::
  183. (Required, integer)
  184. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean-default]
  185. `feature_name`::::
  186. (Required, string)
  187. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-feat-name]
  188. `field`::::
  189. (Required, string)
  190. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-field]
  191. `target_map`::::
  192. (Required, object)
  193. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors-target-mean-map]
  194. =======
  195. ======
  196. `gamma`::::
  197. (Optional, double)
  198. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=gamma]
  199. `lambda`::::
  200. (Optional, double)
  201. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=lambda]
  202. `max_optimization_rounds_per_hyperparameter`::::
  203. (Optional, integer)
  204. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-max-optimization-rounds]
  205. `max_trees`::::
  206. (Optional, integer)
  207. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees]
  208. `num_top_classes`::::
  209. (Optional, integer)
  210. Defines the number of categories for which the predicted probabilities are
  211. reported. It must be non-negative or -1. If it is -1 or greater than the total
  212. number of categories, probabilities are reported for all categories; if you have
  213. a large number of categories, there could be a significant effect on the size of your destination index. Defaults to 2.
  214. +
  215. --
  216. NOTE: To use the
  217. {ml-docs}/ml-dfa-classification.html#ml-dfanalytics-class-aucroc[AUC ROC]
  218. evaluation method, `num_top_classes` must be set to `-1` or a value greater than
  219. or equal to the total number of categories.
  220. --
  221. `num_top_feature_importance_values`::::
  222. (Optional, integer)
  223. Advanced configuration option. Specifies the maximum number of
  224. {ml-docs}/ml-feature-importance.html[{feat-imp}] values per document to return.
  225. By default, it is zero and no {feat-imp} calculation occurs.
  226. `prediction_field_name`::::
  227. (Optional, string)
  228. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=prediction-field-name]
  229. `randomize_seed`::::
  230. (Optional, long)
  231. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=randomize-seed]
  232. `soft_tree_depth_limit`::::
  233. (Optional, double)
  234. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-limit]
  235. `soft_tree_depth_tolerance`::::
  236. (Optional, double)
  237. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-soft-tolerance]
  238. `training_percent`::::
  239. (Optional, integer)
  240. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=training-percent]
  241. //End classification
  242. =====
  243. //Begin outlier_detection
  244. `outlier_detection`:::
  245. (Required^*^, object)
  246. The configuration information necessary to perform
  247. {ml-docs}/ml-dfa-finding-outliers.html[{oldetection}]:
  248. +
  249. .Properties of `outlier_detection`
  250. [%collapsible%open]
  251. =====
  252. `compute_feature_influence`::::
  253. (Optional, Boolean)
  254. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=compute-feature-influence]
  255. `feature_influence_threshold`::::
  256. (Optional, double)
  257. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-influence-threshold]
  258. `method`::::
  259. (Optional, string)
  260. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=method]
  261. `n_neighbors`::::
  262. (Optional, integer)
  263. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=n-neighbors]
  264. `outlier_fraction`::::
  265. (Optional, double)
  266. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=outlier-fraction]
  267. `standardization_enabled`::::
  268. (Optional, Boolean)
  269. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=standardization-enabled]
  270. //End outlier_detection
  271. =====
  272. //Begin regression
  273. `regression`:::
  274. (Required^*^, object)
  275. The configuration information necessary to perform
  276. {ml-docs}/ml-dfa-regression.html[{regression}].
  277. +
  278. TIP: Advanced parameters are for fine-tuning {reganalysis}. They are set
  279. automatically by hyperparameter optimization to give the minimum validation
  280. error. It is highly recommended to use the default values unless you fully
  281. understand the function of these parameters.
  282. +
  283. .Properties of `regression`
  284. [%collapsible%open]
  285. =====
  286. `alpha`::::
  287. (Optional, double)
  288. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-alpha]
  289. `dependent_variable`::::
  290. (Required, string)
  291. +
  292. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dependent-variable]
  293. +
  294. The data type of the field must be numeric.
  295. `downsample_factor`::::
  296. (Optional, double)
  297. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-downsample-factor]
  298. `early_stopping_enabled`::::
  299. (Optional, Boolean)
  300. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-early-stopping-enabled]
  301. `eta`::::
  302. (Optional, double)
  303. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=eta]
  304. `eta_growth_rate_per_tree`::::
  305. (Optional, double)
  306. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-eta-growth]
  307. `feature_bag_fraction`::::
  308. (Optional, double)
  309. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=feature-bag-fraction]
  310. `feature_processors`::::
  311. (Optional, list)
  312. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=dfas-feature-processors]
  313. `gamma`::::
  314. (Optional, double)
  315. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=gamma]
  316. `lambda`::::
  317. (Optional, double)
  318. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=lambda]
  319. `loss_function`::::
  320. (Optional, string)
  321. The loss function used during {regression}. Available options are `mse` (mean
  322. squared error), `msle` (mean squared logarithmic error), `huber` (Pseudo-Huber
  323. loss). Defaults to `mse`.
  324. Refer to
  325. {ml-docs}/dfa-regression-lossfunction.html[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. "create_time" : 1656364565517,
  564. "version" : "8.4.0",
  565. "authorization" : {
  566. "roles" : [
  567. "superuser"
  568. ]
  569. },
  570. "description" : "Outlier detection on log data",
  571. "source" : {
  572. "index" : [
  573. "logdata"
  574. ],
  575. "query" : {
  576. "match_all" : { }
  577. }
  578. },
  579. "dest" : {
  580. "index" : "logdata_out",
  581. "results_field" : "ml"
  582. },
  583. "analysis" : {
  584. "outlier_detection" : {
  585. "compute_feature_influence" : true,
  586. "outlier_fraction" : 0.05,
  587. "standardization_enabled" : true
  588. }
  589. },
  590. "model_memory_limit" : "1gb",
  591. "allow_lazy_start" : false,
  592. "max_num_threads" : 1
  593. }
  594. ----
  595. // TESTRESPONSE[s/1656364565517/$body.$_path/]
  596. // TESTRESPONSE[s/"version": "8.4.0"/"version": $body.version/]
  597. // TESTRESPONSE[s/"authorization" : \{[^}]*\},//]
  598. [[ml-put-dfanalytics-example-r]]
  599. === {regression-cap} examples
  600. The following example creates the `house_price_regression_analysis`
  601. {dfanalytics-job}, the analysis type is `regression`:
  602. [source,console]
  603. --------------------------------------------------
  604. PUT _ml/data_frame/analytics/house_price_regression_analysis
  605. {
  606. "source": {
  607. "index": "houses_sold_last_10_yrs"
  608. },
  609. "dest": {
  610. "index": "house_price_predictions"
  611. },
  612. "analysis":
  613. {
  614. "regression": {
  615. "dependent_variable": "price"
  616. }
  617. }
  618. }
  619. --------------------------------------------------
  620. // TEST[setup:setup_houseprices]
  621. The API returns the following result:
  622. [source,console-result]
  623. ----
  624. {
  625. "id" : "house_price_regression_analysis",
  626. "create_time" : 1656364845151,
  627. "version" : "8.4.0",
  628. "authorization" : {
  629. "roles" : [
  630. "superuser"
  631. ]
  632. },
  633. "source" : {
  634. "index" : [
  635. "houses_sold_last_10_yrs"
  636. ],
  637. "query" : {
  638. "match_all" : { }
  639. }
  640. },
  641. "dest" : {
  642. "index" : "house_price_predictions",
  643. "results_field" : "ml"
  644. },
  645. "analysis" : {
  646. "regression" : {
  647. "dependent_variable" : "price",
  648. "prediction_field_name" : "price_prediction",
  649. "training_percent" : 100.0,
  650. "randomize_seed" : -3578554885299300212,
  651. "loss_function" : "mse",
  652. "early_stopping_enabled" : true
  653. }
  654. },
  655. "model_memory_limit" : "1gb",
  656. "allow_lazy_start" : false,
  657. "max_num_threads" : 1
  658. }
  659. ----
  660. // TESTRESPONSE[s/1656364845151/$body.$_path/]
  661. // TESTRESPONSE[s/"version": "8.4.0"/"version": $body.version/]
  662. // TESTRESPONSE[s/"authorization" : \{[^}]*\},//]
  663. // TESTRESPONSE[s/-3578554885299300212/$body.$_path/]
  664. The following example creates a job and specifies a training percent:
  665. [source,console]
  666. --------------------------------------------------
  667. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  668. {
  669. "source": {
  670. "index": "student_performance_mathematics"
  671. },
  672. "dest": {
  673. "index":"student_performance_mathematics_reg"
  674. },
  675. "analysis":
  676. {
  677. "regression": {
  678. "dependent_variable": "G3",
  679. "training_percent": 70, <1>
  680. "randomize_seed": 19673948271 <2>
  681. }
  682. }
  683. }
  684. --------------------------------------------------
  685. // TEST[skip:TBD]
  686. <1> The percentage of the data set that is used for training the model.
  687. <2> The seed that is used to randomly pick which data is used for training.
  688. The following example uses custom feature processors to transform the
  689. categorical values for `DestWeather` into numerical values using one-hot,
  690. target-mean, and frequency encoding techniques:
  691. [source,console]
  692. --------------------------------------------------
  693. PUT _ml/data_frame/analytics/flight_prices
  694. {
  695. "source": {
  696. "index": [
  697. "kibana_sample_data_flights"
  698. ]
  699. },
  700. "dest": {
  701. "index": "kibana_sample_flight_prices"
  702. },
  703. "analysis": {
  704. "regression": {
  705. "dependent_variable": "AvgTicketPrice",
  706. "num_top_feature_importance_values": 2,
  707. "feature_processors": [
  708. {
  709. "frequency_encoding": {
  710. "field": "DestWeather",
  711. "feature_name": "DestWeather_frequency",
  712. "frequency_map": {
  713. "Rain": 0.14604811155570188,
  714. "Heavy Fog": 0.14604811155570188,
  715. "Thunder & Lightning": 0.14604811155570188,
  716. "Cloudy": 0.14604811155570188,
  717. "Damaging Wind": 0.14604811155570188,
  718. "Hail": 0.14604811155570188,
  719. "Sunny": 0.14604811155570188,
  720. "Clear": 0.14604811155570188
  721. }
  722. }
  723. },
  724. {
  725. "target_mean_encoding": {
  726. "field": "DestWeather",
  727. "feature_name": "DestWeather_targetmean",
  728. "target_map": {
  729. "Rain": 626.5588814585794,
  730. "Heavy Fog": 626.5588814585794,
  731. "Thunder & Lightning": 626.5588814585794,
  732. "Hail": 626.5588814585794,
  733. "Damaging Wind": 626.5588814585794,
  734. "Cloudy": 626.5588814585794,
  735. "Clear": 626.5588814585794,
  736. "Sunny": 626.5588814585794
  737. },
  738. "default_value": 624.0249512020454
  739. }
  740. },
  741. {
  742. "one_hot_encoding": {
  743. "field": "DestWeather",
  744. "hot_map": {
  745. "Rain": "DestWeather_Rain",
  746. "Heavy Fog": "DestWeather_Heavy Fog",
  747. "Thunder & Lightning": "DestWeather_Thunder & Lightning",
  748. "Cloudy": "DestWeather_Cloudy",
  749. "Damaging Wind": "DestWeather_Damaging Wind",
  750. "Hail": "DestWeather_Hail",
  751. "Clear": "DestWeather_Clear",
  752. "Sunny": "DestWeather_Sunny"
  753. }
  754. }
  755. }
  756. ]
  757. }
  758. },
  759. "analyzed_fields": {
  760. "includes": [
  761. "AvgTicketPrice",
  762. "Cancelled",
  763. "DestWeather",
  764. "FlightDelayMin",
  765. "DistanceMiles"
  766. ]
  767. },
  768. "model_memory_limit": "30mb"
  769. }
  770. --------------------------------------------------
  771. // TEST[skip:TBD]
  772. NOTE: These custom feature processors are optional; automatic
  773. {ml-docs}/ml-feature-encoding.html[feature encoding] still occurs for all
  774. categorical features.
  775. [[ml-put-dfanalytics-example-c]]
  776. === {classification-cap} example
  777. The following example creates the `loan_classification` {dfanalytics-job}, the
  778. analysis type is `classification`:
  779. [source,console]
  780. --------------------------------------------------
  781. PUT _ml/data_frame/analytics/loan_classification
  782. {
  783. "source" : {
  784. "index": "loan-applicants"
  785. },
  786. "dest" : {
  787. "index": "loan-applicants-classified"
  788. },
  789. "analysis" : {
  790. "classification": {
  791. "dependent_variable": "label",
  792. "training_percent": 75,
  793. "num_top_classes": 2
  794. }
  795. }
  796. }
  797. --------------------------------------------------
  798. // TEST[skip:TBD]