当前位置: 首页>>代码示例>>Python>>正文


Python MulticlassClassificationEvaluator.explainParam方法代码示例

本文整理汇总了Python中pyspark.ml.evaluation.MulticlassClassificationEvaluator.explainParam方法的典型用法代码示例。如果您正苦于以下问题:Python MulticlassClassificationEvaluator.explainParam方法的具体用法?Python MulticlassClassificationEvaluator.explainParam怎么用?Python MulticlassClassificationEvaluator.explainParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyspark.ml.evaluation.MulticlassClassificationEvaluator的用法示例。


在下文中一共展示了MulticlassClassificationEvaluator.explainParam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MulticlassClassificationEvaluator

# 需要导入模块: from pyspark.ml.evaluation import MulticlassClassificationEvaluator [as 别名]
# 或者: from pyspark.ml.evaluation.MulticlassClassificationEvaluator import explainParam [as 别名]
evaluator = MulticlassClassificationEvaluator(labelCol="label", predictionCol="prediction",
                                              metricName="precision")
accuracy = evaluator.evaluate(predictions)
print "Model Accuracy: ", accuracy

# COMMAND ----------

# MAGIC %md
# MAGIC The Evaluator is able to use a few metrics such as f1-score, precision, recall, weightedPrecision and weightedRecall.
# MAGIC 
# MAGIC evaluator.setMetricName("insert_metric_here") can be used to change the metric used to evaluate models.

# COMMAND ----------

evaluator.explainParam("metricName")

# COMMAND ----------

# MAGIC %md
# MAGIC We can also generate a Confusion Matrix to see the results of the predictions better. ConfusionMatrix() works only with RDDs, so we will have to convert our DataFrame of (prediction, label) into a RDD.
# MAGIC 
# MAGIC confusionMatrix() returns a DenseMatrix with the columns representing the predicted class ordered by ascending class label, and each row represents the actual class ordered by ascending class label. The diagonal from top left to bottom right represents the observations that were predicted correctly. 
# MAGIC 
# MAGIC From the above confusion matrix, we observe that all Setosas (class 0) and Versicolors (class 1) have been classified correctly, but there are 10 Virginicas (class 2) that have been wrongly classified as Versicolors.

# COMMAND ----------

from pyspark.mllib.evaluation import MulticlassMetrics
# Create (prediction, label) pairs
predictionAndLabel = predictions.select("prediction", "label").rdd
开发者ID:Inscrutive,项目名称:spark,代码行数:32,代码来源:NaiveBayes.py


注:本文中的pyspark.ml.evaluation.MulticlassClassificationEvaluator.explainParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。