diff options
author | Yanbo Liang <ybliang8@gmail.com> | 2016-06-06 09:36:34 +0100 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-06-06 09:36:34 +0100 |
commit | a95252823e09939b654dd425db38dadc4100bc87 (patch) | |
tree | 3d563d80f9d6c946b882a31145a12383e0b649bf /examples/src/main/scala | |
parent | fd8af397132fa1415a4c19d7f5cb5a41aa6ddb27 (diff) | |
download | spark-a95252823e09939b654dd425db38dadc4100bc87.tar.gz spark-a95252823e09939b654dd425db38dadc4100bc87.tar.bz2 spark-a95252823e09939b654dd425db38dadc4100bc87.zip |
[SPARK-15771][ML][EXAMPLES] Use 'accuracy' rather than 'precision' in many ML examples
## What changes were proposed in this pull request?
Since [SPARK-15617](https://issues.apache.org/jira/browse/SPARK-15617) deprecated ```precision``` in ```MulticlassClassificationEvaluator```, many ML examples broken.
```python
pyspark.sql.utils.IllegalArgumentException: u'MulticlassClassificationEvaluator_4c3bb1d73d8cc0cedae6 parameter metricName given invalid value precision.'
```
We should use ```accuracy``` to replace ```precision``` in these examples.
## How was this patch tested?
Offline tests.
Author: Yanbo Liang <ybliang8@gmail.com>
Closes #13519 from yanboliang/spark-15771.
Diffstat (limited to 'examples/src/main/scala')
6 files changed, 12 insertions, 12 deletions
diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/DecisionTreeClassificationExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/DecisionTreeClassificationExample.scala index b3103ced91..bc6d327593 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/DecisionTreeClassificationExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/DecisionTreeClassificationExample.scala @@ -81,7 +81,7 @@ object DecisionTreeClassificationExample { val evaluator = new MulticlassClassificationEvaluator() .setLabelCol("indexedLabel") .setPredictionCol("prediction") - .setMetricName("precision") + .setMetricName("accuracy") val accuracy = evaluator.evaluate(predictions) println("Test Error = " + (1.0 - accuracy)) diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/GradientBoostedTreeClassifierExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/GradientBoostedTreeClassifierExample.scala index 0d1ffbe225..9a39acfbf3 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/GradientBoostedTreeClassifierExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/GradientBoostedTreeClassifierExample.scala @@ -83,7 +83,7 @@ object GradientBoostedTreeClassifierExample { val evaluator = new MulticlassClassificationEvaluator() .setLabelCol("indexedLabel") .setPredictionCol("prediction") - .setMetricName("precision") + .setMetricName("accuracy") val accuracy = evaluator.evaluate(predictions) println("Test Error = " + (1.0 - accuracy)) diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/MultilayerPerceptronClassifierExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/MultilayerPerceptronClassifierExample.scala index 0e780fb7d3..e8a9b32da9 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/MultilayerPerceptronClassifierExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/MultilayerPerceptronClassifierExample.scala @@ -55,12 +55,12 @@ object MultilayerPerceptronClassifierExample { .setMaxIter(100) // train the model val model = trainer.fit(train) - // compute precision on the test set + // compute accuracy on the test set val result = model.transform(test) val predictionAndLabels = result.select("prediction", "label") val evaluator = new MulticlassClassificationEvaluator() - .setMetricName("precision") - println("Precision:" + evaluator.evaluate(predictionAndLabels)) + .setMetricName("accuracy") + println("Accuracy: " + evaluator.evaluate(predictionAndLabels)) // $example off$ spark.stop() diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/NaiveBayesExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/NaiveBayesExample.scala index 90cdebfcb0..a59ba182fc 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/NaiveBayesExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/NaiveBayesExample.scala @@ -49,9 +49,9 @@ object NaiveBayesExample { val evaluator = new MulticlassClassificationEvaluator() .setLabelCol("label") .setPredictionCol("prediction") - .setMetricName("precision") - val precision = evaluator.evaluate(predictions) - println("Precision:" + precision) + .setMetricName("accuracy") + val accuracy = evaluator.evaluate(predictions) + println("Accuracy: " + accuracy) // $example off$ spark.stop() diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/OneVsRestExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/OneVsRestExample.scala index 0da8e3137a..acde110683 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/OneVsRestExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/OneVsRestExample.scala @@ -65,11 +65,11 @@ object OneVsRestExample { // obtain evaluator. val evaluator = new MulticlassClassificationEvaluator() - .setMetricName("precision") + .setMetricName("accuracy") // compute the classification error on test data. - val precision = evaluator.evaluate(predictions) - println(s"Test Error : ${1 - precision}") + val accuracy = evaluator.evaluate(predictions) + println(s"Test Error : ${1 - accuracy}") // $example off$ spark.stop() diff --git a/examples/src/main/scala/org/apache/spark/examples/ml/RandomForestClassifierExample.scala b/examples/src/main/scala/org/apache/spark/examples/ml/RandomForestClassifierExample.scala index cccc4a6ea2..5eafda8ce4 100644 --- a/examples/src/main/scala/org/apache/spark/examples/ml/RandomForestClassifierExample.scala +++ b/examples/src/main/scala/org/apache/spark/examples/ml/RandomForestClassifierExample.scala @@ -83,7 +83,7 @@ object RandomForestClassifierExample { val evaluator = new MulticlassClassificationEvaluator() .setLabelCol("indexedLabel") .setPredictionCol("prediction") - .setMetricName("precision") + .setMetricName("accuracy") val accuracy = evaluator.evaluate(predictions) println("Test Error = " + (1.0 - accuracy)) |