aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorZheng RuiFeng <ruifengz@foxmail.com>2016-06-06 15:19:22 +0100
committerSean Owen <sowen@cloudera.com>2016-06-06 15:19:22 +0100
commit00ad4f054cd044e17d29b7c2c62efd8616462619 (patch)
tree119be6ea5c41a4535809381b71710be82e348cac /python
parenta95252823e09939b654dd425db38dadc4100bc87 (diff)
downloadspark-00ad4f054cd044e17d29b7c2c62efd8616462619.tar.gz
spark-00ad4f054cd044e17d29b7c2c62efd8616462619.tar.bz2
spark-00ad4f054cd044e17d29b7c2c62efd8616462619.zip
[SPARK-14900][ML][PYSPARK] Add accuracy and deprecate precison,recall,f1
## What changes were proposed in this pull request? 1, add accuracy for MulticlassMetrics 2, deprecate overall precision,recall,f1 and recommend accuracy usage ## How was this patch tested? manual tests in pyspark shell Author: Zheng RuiFeng <ruifengz@foxmail.com> Closes #13511 from zhengruifeng/deprecate_py_precisonrecall.
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/mllib/evaluation.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/python/pyspark/mllib/evaluation.py b/python/pyspark/mllib/evaluation.py
index 5f32f092c7..2eaac87b67 100644
--- a/python/pyspark/mllib/evaluation.py
+++ b/python/pyspark/mllib/evaluation.py
@@ -15,6 +15,8 @@
# limitations under the License.
#
+import warnings
+
from pyspark import since
from pyspark.mllib.common import JavaModelWrapper, callMLlibFunc
from pyspark.sql import SQLContext
@@ -181,6 +183,8 @@ class MulticlassMetrics(JavaModelWrapper):
0.66...
>>> metrics.recall()
0.66...
+ >>> metrics.accuracy()
+ 0.66...
>>> metrics.weightedFalsePositiveRate
0.19...
>>> metrics.weightedPrecision
@@ -233,6 +237,8 @@ class MulticlassMetrics(JavaModelWrapper):
Returns precision or precision for a given label (category) if specified.
"""
if label is None:
+ # note:: Deprecated in 2.0.0. Use accuracy.
+ warnings.warn("Deprecated in 2.0.0. Use accuracy.")
return self.call("precision")
else:
return self.call("precision", float(label))
@@ -243,6 +249,8 @@ class MulticlassMetrics(JavaModelWrapper):
Returns recall or recall for a given label (category) if specified.
"""
if label is None:
+ # note:: Deprecated in 2.0.0. Use accuracy.
+ warnings.warn("Deprecated in 2.0.0. Use accuracy.")
return self.call("recall")
else:
return self.call("recall", float(label))
@@ -254,6 +262,8 @@ class MulticlassMetrics(JavaModelWrapper):
"""
if beta is None:
if label is None:
+ # note:: Deprecated in 2.0.0. Use accuracy.
+ warnings.warn("Deprecated in 2.0.0. Use accuracy.")
return self.call("fMeasure")
else:
return self.call("fMeasure", label)
@@ -263,6 +273,14 @@ class MulticlassMetrics(JavaModelWrapper):
else:
return self.call("fMeasure", label, beta)
+ @since('2.0.0')
+ def accuracy(self):
+ """
+ Returns accuracy (equals to the total number of correctly classified instances
+ out of the total number of instances).
+ """
+ return self.call("accuracy")
+
@property
@since('1.4.0')
def weightedTruePositiveRate(self):