Evaluate data frame analytics API

Evaluates the data frame analytics for an annotated index.

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Request

POST _ml/data_frame/_evaluate

Prerequisites

If the Elasticsearch security features are enabled, you must have the following privileges:

  • cluster: monitor_ml

For more information, see Security privileges and Machine learning security privileges.

Description

The API packages together commonly used evaluation metrics for various types of machine learning features. This has been designed for use on indexes created by data frame analytics. Evaluation requires both a ground truth field and an analytics result field to be present.

Request body

evaluation

(Required, object) Defines the type of evaluation you want to perform. See Data frame analytics evaluation resources.

Available evaluation types:

  • binary_soft_classification
  • regression
  • classification

index

(Required, object) Defines the index in which the evaluation will be performed.

query

(Optional, object) A query clause that retrieves a subset of data from the source index. See Query DSL.

Data frame analytics evaluation resources

Binary soft classification evaluation objects

Binary soft classification evaluates the results of an analysis which outputs the probability that each document belongs to a certain class. For example, in the context of outlier detection, the analysis outputs the probability whether each document is an outlier.

actual_field

(Required, string) The field of the index which contains the ground truth. The data type of this field can be boolean or integer. If the data type is integer, the value has to be either 0 (false) or 1 (true).

predicted_probability_field

(Required, string) The field of the index that defines the probability of whether the item belongs to the class in question or not. It’s the field that contains the results of the analysis.

metrics

(Optional, object) Specifies the metrics that are used for the evaluation. Available metrics:

  • auc_roc

    (Optional, object) The AUC ROC (area under the curve of the receiver operating characteristic) score and optionally the curve. Default value is {“includes_curve”: false}.

    confusion_matrix

    (Optional, object) Set the different thresholds of the outlier score at where the metrics (tp - true positive, fp - false positive, tn - true negative, fn - false negative) are calculated. Default value is {“at”: [0.25, 0.50, 0.75]}.

    precision

    (Optional, object) Set the different thresholds of the outlier score at where the metric is calculated. Default value is {“at”: [0.25, 0.50, 0.75]}.

    recall

    (Optional, object) Set the different thresholds of the outlier score at where the metric is calculated. Default value is {“at”: [0.25, 0.50, 0.75]}.

Regression evaluation objects

Regression evaluation evaluates the results of a regression analysis which outputs a prediction of values.

actual_field

(Required, string) The field of the index which contains the ground truth. The data type of this field must be numerical.

predicted_field

(Required, string) The field in the index that contains the predicted value, in other words the results of the regression analysis.

metrics

(Optional, object) Specifies the metrics that are used for the evaluation. Available metrics:

  • mse

    (Optional, object) Average squared difference between the predicted values and the actual (ground truth) value. For more information, read this wiki article.

    msle

    (Optional, object) Average squared difference between the logarithm of the predicted values and the logarithm of the actual (ground truth) value.

    huber

    (Optional, object) Pseudo Huber loss function. For more information, read this wiki article.

    r_squared

    (Optional, object) Proportion of the variance in the dependent variable that is predictable from the independent variables. For more information, read this wiki article.

Classification evaluation objects

Classification evaluation evaluates the results of a classification analysis which outputs a prediction that identifies to which of the classes each document belongs.

actual_field

(Required, string) The field of the index which contains the ground truth. The data type of this field must be categorical.

predicted_field

(Required, string) The field in the index that contains the predicted value, in other words the results of the classification analysis.

metrics

(Optional, object) Specifies the metrics that are used for the evaluation. Available metrics:

  • accuracy

    (Optional, object) Accuracy of predictions (per-class and overall).

    multiclass_confusion_matrix

    (Optional, object) Multiclass confusion matrix.

    precision

    (Optional, object) Precision of predictions (per-class and average).

    recall

    (Optional, object) Recall of predictions (per-class and average).

Examples

Binary soft classification

  1. POST _ml/data_frame/_evaluate
  2. {
  3. "index": "my_analytics_dest_index",
  4. "evaluation": {
  5. "binary_soft_classification": {
  6. "actual_field": "is_outlier",
  7. "predicted_probability_field": "ml.outlier_score"
  8. }
  9. }
  10. }

The API returns the following results:

  1. {
  2. "binary_soft_classification": {
  3. "auc_roc": {
  4. "score": 0.92584757746414444
  5. },
  6. "confusion_matrix": {
  7. "0.25": {
  8. "tp": 5,
  9. "fp": 9,
  10. "tn": 204,
  11. "fn": 5
  12. },
  13. "0.5": {
  14. "tp": 1,
  15. "fp": 5,
  16. "tn": 208,
  17. "fn": 9
  18. },
  19. "0.75": {
  20. "tp": 0,
  21. "fp": 4,
  22. "tn": 209,
  23. "fn": 10
  24. }
  25. },
  26. "precision": {
  27. "0.25": 0.35714285714285715,
  28. "0.5": 0.16666666666666666,
  29. "0.75": 0
  30. },
  31. "recall": {
  32. "0.25": 0.5,
  33. "0.5": 0.1,
  34. "0.75": 0
  35. }
  36. }
  37. }

Regression

  1. POST _ml/data_frame/_evaluate
  2. {
  3. "index": "house_price_predictions",
  4. "query": {
  5. "bool": {
  6. "filter": [
  7. { "term": { "ml.is_training": false } }
  8. ]
  9. }
  10. },
  11. "evaluation": {
  12. "regression": {
  13. "actual_field": "price",
  14. "predicted_field": "ml.price_prediction",
  15. "metrics": {
  16. "r_squared": {},
  17. "mse": {}
  18. }
  19. }
  20. }
  21. }

The output destination index from a data frame analytics regression analysis.

In this example, a test/train split (training_percent) was defined for the regression analysis. This query limits evaluation to be performed on the test split only.

The ground truth value for the actual house price. This is required in order to evaluate results.

The predicted value for house price calculated by the regression analysis.

The following example calculates the training error:

  1. POST _ml/data_frame/_evaluate
  2. {
  3. "index": "student_performance_mathematics_reg",
  4. "query": {
  5. "term": {
  6. "ml.is_training": {
  7. "value": true
  8. }
  9. }
  10. },
  11. "evaluation": {
  12. "regression": {
  13. "actual_field": "G3",
  14. "predicted_field": "ml.G3_prediction",
  15. "metrics": {
  16. "r_squared": {},
  17. "mse": {}
  18. }
  19. }
  20. }
  21. }

In this example, a test/train split (training_percent) was defined for the regression analysis. This query limits evaluation to be performed on the train split only. It means that a training error will be calculated.

The field that contains the ground truth value for the actual student performance. This is required in order to evaluate results.

The field that contains the predicted value for student performance calculated by the regression analysis.

The next example calculates the testing error. The only difference compared with the previous example is that ml.is_training is set to false this time, so the query excludes the train split from the evaluation.

  1. POST _ml/data_frame/_evaluate
  2. {
  3. "index": "student_performance_mathematics_reg",
  4. "query": {
  5. "term": {
  6. "ml.is_training": {
  7. "value": false
  8. }
  9. }
  10. },
  11. "evaluation": {
  12. "regression": {
  13. "actual_field": "G3",
  14. "predicted_field": "ml.G3_prediction",
  15. "metrics": {
  16. "r_squared": {},
  17. "mse": {}
  18. }
  19. }
  20. }
  21. }

In this example, a test/train split (training_percent) was defined for the regression analysis. This query limits evaluation to be performed on the test split only. It means that a testing error will be calculated.

The field that contains the ground truth value for the actual student performance. This is required in order to evaluate results.

The field that contains the predicted value for student performance calculated by the regression analysis.

Classification

  1. POST _ml/data_frame/_evaluate
  2. {
  3. "index": "animal_classification",
  4. "evaluation": {
  5. "classification": {
  6. "actual_field": "animal_class",
  7. "predicted_field": "ml.animal_class_prediction",
  8. "metrics": {
  9. "multiclass_confusion_matrix" : {}
  10. }
  11. }
  12. }
  13. }

The evaluation type.

The field that contains the ground truth value for the actual animal classification. This is required in order to evaluate results.

The field that contains the predicted value for animal classification by the classification analysis.

Specifies the metric for the evaluation.

The API returns the following result:

  1. {
  2. "classification" : {
  3. "multiclass_confusion_matrix" : {
  4. "confusion_matrix" : [
  5. {
  6. "actual_class" : "cat",
  7. "actual_class_doc_count" : 12,
  8. "predicted_classes" : [
  9. {
  10. "predicted_class" : "cat",
  11. "count" : 12
  12. },
  13. {
  14. "predicted_class" : "dog",
  15. "count" : 0
  16. }
  17. ],
  18. "other_predicted_class_doc_count" : 0
  19. },
  20. {
  21. "actual_class" : "dog",
  22. "actual_class_doc_count" : 11,
  23. "predicted_classes" : [
  24. {
  25. "predicted_class" : "dog",
  26. "count" : 7
  27. },
  28. {
  29. "predicted_class" : "cat",
  30. "count" : 4
  31. }
  32. ],
  33. "other_predicted_class_doc_count" : 0
  34. }
  35. ],
  36. "other_actual_class_count" : 0
  37. }
  38. }
  39. }

The name of the actual class that the analysis tried to predict.

The number of documents in the index that belong to the actual_class.

This object contains the list of the predicted classes and the number of predictions associated with the class.

The number of cats in the dataset that are correctly identified as cats.

The number of cats in the dataset that are incorrectly classified as dogs.

The number of documents that are classified as a class that is not listed as a predicted_class.