put-dfanalytics.asciidoc 26 KB

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