evaluator for binary classification

Solutions on MaxInterview for evaluator for binary classification by the best coders in the world

showing results for - "evaluator for binary classification"
Jonathan
25 Mar 2018
1# Evaluator for binary classification
2
3from pyspark.ml.linalg import Vectors
4scoreAndLabels = map(lambda x: (Vectors.dense(
5  [1.0 - x[0], x[0]]), x[1]), [
6  (0.1, 0.0), (0.1, 1.0), (0.4, 0.0), (0.6, 0.0), (0.6, 1.0), (0.6, 1.0), (0.8, 1.0)])
7dataset = spark.createDataFrame(scoreAndLabels, ["raw", "label"])
8# ...
9evaluator = BinaryClassificationEvaluator(rawPredictionCol="raw")
10evaluator.evaluate(dataset)
11# 0.70...
12evaluator.evaluate(dataset, {evaluator.metricName: "areaUnderPR"})
13# 0.83...
14bce_path = temp_path + "/bce"
15evaluator.save(bce_path)
16evaluator2 = BinaryClassificationEvaluator.load(bce_path)
17str(evaluator2.getRawPredictionCol())
18# 'raw'