loss functions for multiclass classification code example

Example: Evaluator for Multiclass Classification

# Evaluator for Multiclass Classification

scoreAndLabels = [(0.0, 0.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (1.0, 1.0), (1.0, 1.0), (2.0, 2.0), (2.0, 0.0)]
dataset = spark.createDataFrame(scoreAndLabels, ["prediction", "label"])
# ...
evaluator = MulticlassClassificationEvaluator(predictionCol="prediction")
evaluator.evaluate(dataset)
# 0.55...
evaluate.evaluate(dataset, {evaluator.metricName: "accuracy"})
# 0.66...
mce_path = temp_path + "/mce"
evaluator.save(mce_path)
evaluator2 = MulticlassClassificationvaluator.load(mce_path)
str(evaluator2.getPredictionCol())
'prediction'