Skip to content
Snippets Groups Projects
Commit 00ad4f05 authored by Zheng RuiFeng's avatar Zheng RuiFeng Committed by Sean Owen
Browse files

[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.
parent a9525282
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# limitations under the License. # limitations under the License.
# #
import warnings
from pyspark import since from pyspark import since
from pyspark.mllib.common import JavaModelWrapper, callMLlibFunc from pyspark.mllib.common import JavaModelWrapper, callMLlibFunc
from pyspark.sql import SQLContext from pyspark.sql import SQLContext
...@@ -181,6 +183,8 @@ class MulticlassMetrics(JavaModelWrapper): ...@@ -181,6 +183,8 @@ class MulticlassMetrics(JavaModelWrapper):
0.66... 0.66...
>>> metrics.recall() >>> metrics.recall()
0.66... 0.66...
>>> metrics.accuracy()
0.66...
>>> metrics.weightedFalsePositiveRate >>> metrics.weightedFalsePositiveRate
0.19... 0.19...
>>> metrics.weightedPrecision >>> metrics.weightedPrecision
...@@ -233,6 +237,8 @@ class MulticlassMetrics(JavaModelWrapper): ...@@ -233,6 +237,8 @@ class MulticlassMetrics(JavaModelWrapper):
Returns precision or precision for a given label (category) if specified. Returns precision or precision for a given label (category) if specified.
""" """
if label 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("precision") return self.call("precision")
else: else:
return self.call("precision", float(label)) return self.call("precision", float(label))
...@@ -243,6 +249,8 @@ class MulticlassMetrics(JavaModelWrapper): ...@@ -243,6 +249,8 @@ class MulticlassMetrics(JavaModelWrapper):
Returns recall or recall for a given label (category) if specified. Returns recall or recall for a given label (category) if specified.
""" """
if label 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("recall") return self.call("recall")
else: else:
return self.call("recall", float(label)) return self.call("recall", float(label))
...@@ -254,6 +262,8 @@ class MulticlassMetrics(JavaModelWrapper): ...@@ -254,6 +262,8 @@ class MulticlassMetrics(JavaModelWrapper):
""" """
if beta is None: if beta is None:
if label 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") return self.call("fMeasure")
else: else:
return self.call("fMeasure", label) return self.call("fMeasure", label)
...@@ -263,6 +273,14 @@ class MulticlassMetrics(JavaModelWrapper): ...@@ -263,6 +273,14 @@ class MulticlassMetrics(JavaModelWrapper):
else: else:
return self.call("fMeasure", label, beta) 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 @property
@since('1.4.0') @since('1.4.0')
def weightedTruePositiveRate(self): def weightedTruePositiveRate(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment