-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make accuracy evaluation metric work when there is field mapping type…
… mismatch
- Loading branch information
1 parent
060b4ee
commit 8e66ea3
Showing
5 changed files
with
207 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../org/elasticsearch/xpack/core/ml/dataframe/evaluation/classification/PainlessScripts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ml.dataframe.evaluation.classification; | ||
|
||
import org.elasticsearch.script.Script; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Painless scripts used by classification metrics in this package. | ||
*/ | ||
final class PainlessScripts { | ||
|
||
/** | ||
* Template for the comparison script. | ||
* It uses "String.valueOf" method in case the mapping types of the two fields are different. | ||
*/ | ||
private static final MessageFormat COMPARISON_SCRIPT_TEMPLATE = | ||
new MessageFormat("String.valueOf(doc[''{0}''].value).equals(String.valueOf(doc[''{1}''].value))", Locale.ROOT); | ||
|
||
/** | ||
* Builds field comparison script for the given actual and predicted field names. | ||
* @param actualField name of the actual field | ||
* @param predictedField name of the predicted field | ||
* @return script that compares values of actualField and predictedField | ||
*/ | ||
static Script buildComparisonScript(String actualField, String predictedField) { | ||
return new Script(COMPARISON_SCRIPT_TEMPLATE.format(new Object[]{ actualField, predictedField })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.