pyspark ,BinaryClassificationMtrics返回值对象的属性有什么·,如何进行输出
时间: 2023-12-03 19:45:43 浏览: 31
在 PySpark 中,BinaryClassificationMetrics 返回值对象包含以下属性:
- areaUnderROC: ROC曲线下的面积。
- areaUnderPR: PR曲线下的面积。
- thresholds: 阈值列表。
- fMeasureByThreshold: 按阈值计算的F1分数。
- precisionByThreshold: 按阈值计算的精度。
- recallByThreshold: 按阈值计算的召回率。
- roc: ROC曲线点的(x, y)坐标对列表。
- pr: PR曲线点的(x, y)坐标对列表。
要输出这些属性,可以使用以下方法:
```python
from pyspark.mllib.evaluation import BinaryClassificationMetrics
# 假设已经有了真实标签和预测标签
metrics = BinaryClassificationMetrics(predictions_and_labels)
# 输出areaUnderROC属性
print("Area under ROC = {:.2f}%".format(metrics.areaUnderROC * 100))
# 输出thresholds属性
print("Thresholds = {}".format(metrics.thresholds))
# 输出fMeasureByThreshold属性
print("F-measure by threshold = {}".format(metrics.fMeasureByThreshold))
# 输出roc属性
print("ROC curve = {}".format(metrics.roc))
```
注意,`predictions_and_labels` 是一个 RDD,其中每个元素都是一个 (预测标签, 真实标签) 的元组。`areaUnderROC` 属性是一个浮点数,其余属性都是列表。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)