Why the Accuracy and Weighted Recall values are sa

2019-08-29 07:46发布

In my Naive Bayes implementation with using Apache Spark, I get same values for accuracy and weighted recall values all the times.

I implemented Naive Bayes algorithm from Spark's tutorials and it works fine except the thing that I mentioned above.

        Dataset<Row>[] splits = dataFrame.randomSplit(new double[]
                {mainController.getTrainingDataRate(), mainController.getTestDataRate()});
        Dataset<Row> train = splits[0];
        Dataset<Row> test = splits[1];

        NaiveBayes nb = new NaiveBayes();
        NaiveBayesModel model = nb.fit(train);

        Dataset<Row> predictions = model.transform(test);

        MulticlassClassificationEvaluator evaluator = new MulticlassClassificationEvaluator()
                .setLabelCol("label")
                .setPredictionCol("prediction")
                .setMetricName("weightedPrecision");

        precisionSum += (evaluator.evaluate(predictions));

        evaluator.setMetricName("weightedRecall");
        recallSum += (evaluator.evaluate(predictions));

        evaluator.setMetricName("accuracy");
        accuracySum += (evaluator.evaluate(predictions));  

I run the code above hundred times and in every of them accuracy results were equal to weighted recall values even I tried in different data files which consists of hundreds of thousands rows. Where am I doing wrong?

1条回答
聊天终结者
2楼-- · 2019-08-29 08:08

For single task classification, micro-averaged recall(so-called weighted recall) is always the same with accuracy.

查看更多
登录 后发表回答