get-trained-models.asciidoc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[get-trained-models]]
  4. = Get trained models API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Get trained models</titleabbrev>
  8. ++++
  9. Retrieves configuration information for a trained model.
  10. [[ml-get-trained-models-request]]
  11. == {api-request-title}
  12. `GET _ml/trained_models/` +
  13. `GET _ml/trained_models/<model_id>` +
  14. `GET _ml/trained_models/_all` +
  15. `GET _ml/trained_models/<model_id1>,<model_id2>` +
  16. `GET _ml/trained_models/<model_id_pattern*>`
  17. [[ml-get-trained-models-prereq]]
  18. == {api-prereq-title}
  19. Requires the `monitor_ml` cluster privilege. This privilege is included in the
  20. `machine_learning_user` built-in role.
  21. [[ml-get-trained-models-desc]]
  22. == {api-description-title}
  23. You can get information for multiple trained models in a single API request by
  24. using a comma-separated list of model IDs or a wildcard expression.
  25. [[ml-get-trained-models-path-params]]
  26. == {api-path-parms-title}
  27. `<model_id>`::
  28. (Optional, string)
  29. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id-or-alias]
  30. [[ml-get-trained-models-query-params]]
  31. == {api-query-parms-title}
  32. `allow_no_match`::
  33. (Optional, Boolean)
  34. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-match-models]
  35. `decompress_definition`::
  36. (Optional, Boolean)
  37. Specifies whether the included model definition should be returned as a JSON map
  38. (`true`) or in a custom compressed format (`false`). Defaults to `true`.
  39. `exclude_generated`::
  40. (Optional, Boolean)
  41. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=exclude-generated]
  42. `from`::
  43. (Optional, integer)
  44. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=from-models]
  45. `include`::
  46. (Optional, string)
  47. A comma delimited string of optional fields to include in the response body. The
  48. default value is empty, indicating no optional fields are included. Valid
  49. options are:
  50. - `definition`: Includes the model definition.
  51. - `feature_importance_baseline`: Includes the baseline for {feat-imp} values.
  52. - `hyperparameters`: Includes the information about hyperparameters used to
  53. train the model. This information consists of the value, the absolute and
  54. relative importance of the hyperparameter as well as an indicator of whether
  55. it was specified by the user or tuned during hyperparameter optimization.
  56. - `total_feature_importance`: Includes the total {feat-imp} for the training
  57. data set.
  58. The baseline and total {feat-imp} values are returned in the `metadata` field
  59. in the response body.
  60. `size`::
  61. (Optional, integer)
  62. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=size-models]
  63. `tags`::
  64. (Optional, string)
  65. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=tags]
  66. [role="child_attributes"]
  67. [[ml-get-trained-models-results]]
  68. == {api-response-body-title}
  69. `trained_model_configs`::
  70. (array)
  71. An array of trained model resources, which are sorted by the `model_id` value in
  72. ascending order.
  73. +
  74. .Properties of trained model resources
  75. [%collapsible%open]
  76. ====
  77. `created_by`:::
  78. (string)
  79. Information on the creator of the trained model.
  80. `create_time`:::
  81. (<<time-units,time units>>)
  82. The time when the trained model was created.
  83. `default_field_map` :::
  84. (object)
  85. A string to string object that contains the default field map to use
  86. when inferring against the model. For example, data frame analytics
  87. may train the model on a specific multi-field `foo.keyword`.
  88. The analytics job would then supply a default field map entry for
  89. `"foo" : "foo.keyword"`.
  90. +
  91. Any field map described in the inference configuration takes precedence.
  92. `description`:::
  93. (string)
  94. The free-text description of the trained model.
  95. `estimated_heap_memory_usage_bytes`:::
  96. (integer)
  97. The estimated heap usage in bytes to keep the trained model in memory.
  98. `estimated_operations`:::
  99. (integer)
  100. The estimated number of operations to use the trained model.
  101. `inference_config`:::
  102. (object)
  103. The default configuration for inference. This can be either a `regression`
  104. or `classification` configuration. It must match the underlying
  105. `definition.trained_model`'s `target_type`.
  106. +
  107. .Properties of `inference_config`
  108. [%collapsible%open]
  109. =====
  110. `classification`::::
  111. (object)
  112. Classification configuration for inference.
  113. +
  114. .Properties of classification inference
  115. [%collapsible%open]
  116. ======
  117. `num_top_classes`:::
  118. (integer)
  119. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  120. `num_top_feature_importance_values`:::
  121. (integer)
  122. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  123. `prediction_field_type`:::
  124. (string)
  125. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  126. `results_field`:::
  127. (string)
  128. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  129. `top_classes_results_field`:::
  130. (string)
  131. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  132. ======
  133. `regression`::::
  134. (object)
  135. Regression configuration for inference.
  136. +
  137. .Properties of regression inference
  138. [%collapsible%open]
  139. ======
  140. `num_top_feature_importance_values`:::
  141. (integer)
  142. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  143. `results_field`:::
  144. (string)
  145. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  146. ======
  147. =====
  148. `input`:::
  149. (object)
  150. The input field names for the model definition.+
  151. +
  152. .Properties of `input`
  153. [%collapsible%open]
  154. =====
  155. `field_names`::::
  156. (string)
  157. An array of input field names for the model.
  158. =====
  159. `license_level`:::
  160. (string)
  161. The license level of the trained model.
  162. `metadata`:::
  163. (object)
  164. An object containing metadata about the trained model. For example, models
  165. created by {dfanalytics} contain `analysis_config` and `input` objects.
  166. +
  167. .Properties of metadata
  168. [%collapsible%open]
  169. =====
  170. `feature_importance_baseline`:::
  171. (object)
  172. An object that contains the baseline for {feat-imp} values. For {reganalysis},
  173. it is a single value. For {classanalysis}, there is a value for each class.
  174. `hyperparameters`:::
  175. (array)
  176. List of the available hyperparameters optimized during the
  177. `fine_parameter_tuning` phase as well as specified by the user.
  178. +
  179. .Properties of hyperparameters
  180. [%collapsible%open]
  181. ======
  182. `absolute_importance`::::
  183. (double)
  184. A positive number showing how much the parameter influences the variation of the
  185. loss function. For hyperparameters with values that are not specified by the
  186. user but tuned during hyperparameter optimization.
  187. `max_trees`::::
  188. (integer)
  189. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees-trained-models]
  190. `name`::::
  191. (string)
  192. Name of the hyperparameter.
  193. `relative_importance`::::
  194. (double)
  195. A number between 0 and 1 showing the proportion of influence on the variation of
  196. the loss function among all tuned hyperparameters. For hyperparameters with
  197. values that are not specified by the user but tuned during hyperparameter
  198. optimization.
  199. `supplied`::::
  200. (Boolean)
  201. Indicates if the hyperparameter is specified by the user (`true`) or optimized
  202. (`false`).
  203. `value`::::
  204. (double)
  205. The value of the hyperparameter, either optimized or specified by the user.
  206. ======
  207. `total_feature_importance`:::
  208. (array)
  209. An array of the total {feat-imp} for each feature used from
  210. the training data set. This array of objects is returned if {dfanalytics} trained
  211. the model and the request includes `total_feature_importance` in the `include`
  212. request parameter.
  213. +
  214. .Properties of total {feat-imp}
  215. [%collapsible%open]
  216. ======
  217. `feature_name`:::
  218. (string)
  219. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-feature-name]
  220. `importance`:::
  221. (object)
  222. A collection of {feat-imp} statistics related to the training data set for this particular feature.
  223. +
  224. .Properties of {feat-imp}
  225. [%collapsible%open]
  226. =======
  227. `mean_magnitude`:::
  228. (double)
  229. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-magnitude]
  230. `max`:::
  231. (integer)
  232. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-max]
  233. `min`:::
  234. (integer)
  235. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-min]
  236. =======
  237. `classes`:::
  238. (array)
  239. If the trained model is a classification model, {feat-imp} statistics are gathered
  240. per target class value.
  241. +
  242. .Properties of class {feat-imp}
  243. [%collapsible%open]
  244. =======
  245. `class_name`:::
  246. (string)
  247. The target class value. Could be a string, boolean, or number.
  248. `importance`:::
  249. (object)
  250. A collection of {feat-imp} statistics related to the training data set for this particular feature.
  251. +
  252. .Properties of {feat-imp}
  253. [%collapsible%open]
  254. ========
  255. `mean_magnitude`:::
  256. (double)
  257. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-magnitude]
  258. `max`:::
  259. (int)
  260. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-max]
  261. `min`:::
  262. (int)
  263. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-min]
  264. ========
  265. =======
  266. ======
  267. =====
  268. `model_id`:::
  269. (string)
  270. Identifier for the trained model.
  271. `tags`:::
  272. (string)
  273. A comma delimited string of tags. A trained model can have many tags, or none.
  274. `version`:::
  275. (string)
  276. The {es} version number in which the trained model was created.
  277. ====
  278. [[ml-get-trained-models-response-codes]]
  279. == {api-response-codes-title}
  280. `400`::
  281. If `include_model_definition` is `true`, this code indicates that more than
  282. one models match the ID pattern.
  283. `404` (Missing resources)::
  284. If `allow_no_match` is `false`, this code indicates that there are no
  285. resources that match the request or only partial matches for the request.
  286. [[ml-get-trained-models-example]]
  287. == {api-examples-title}
  288. The following example gets configuration information for all the trained models:
  289. [source,console]
  290. --------------------------------------------------
  291. GET _ml/trained_models/
  292. --------------------------------------------------
  293. // TEST[skip:TBD]