from pyspark.ml.evaluation import BinaryClassificationEvaluator
from pyspark.mllib.evaluation import BinaryClassificationMetrics, MulticlassMetrics
def print_performance_metrics(predictions):
# Evaluate model
evaluator = BinaryClassificationEvaluator(rawPredictionCol="rawPrediction")
auc = evaluator.evaluate(predictions, {evaluator.metricName: "areaUnderROC"})
aupr = evaluator.evaluate(predictions, {evaluator.metricName: "areaUnderPR"})
print("auc = {}".format(auc))
print("aupr = {}".format(aupr))
# get rdd of predictions and labels for mllib eval metrics
predictionAndLabels = predictions.select("prediction","label").rdd
# Instantiate metrics objects
binary_metrics = BinaryClassificationMetrics(predictionAndLabels)
multi_metrics = MulticlassMetrics(predictionAndLabels)
# Area under precision-recall curve
print("Area under PR = {}".format(binary_metrics.areaUnderPR))
# Area under ROC curve
print("Area under ROC = {}".format(binary_metrics.areaUnderROC))
# Accuracy
print("Accuracy = {}".format(multi_metrics.accuracy))
# Confusion Matrix
print(multi_metrics.confusionMatrix())
### Question F1, Precision Score ###
# F1
print("F1 = {}".format(multi_metrics.fMeasure()))
# Precision
# print("Precision = {}".format(multi_metrics.precision()))
# Recall
# print("Recall = {}".format(multi_metrics.recall()))
# FPR
# print("FPR = {}".format(multi_metrics.falsePositiveRate(0.0)))
# TPR
# print("TPR = {}".for
mat(multi_metrics.truePositiveRate(0.0)))
I am working on the above function for model scores. It gave me the auc and accuracy score but it did not work for multiclassmetrics. I am not able to get the f1 and precision scores it gives
fMeasure() missing 1 required positional argument: 'label'