python使用sklearn的PrecisionRecallDisplay来可视化PR曲线
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python使用sklearn的PrecisionRecallDisplay来可视化PR曲线相关的知识,希望对你有一定的参考价值。
python使用sklearn的PrecisionRecallDisplay来可视化PR曲线
目录
python使用sklearn的PrecisionRecallDisplay来可视化PR曲线
#PrecisionRecallDisplay来可视化PR曲线
#模型构建
print(__doc__)
from sklearn.datasets import fetch_openml
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X, y = fetch_openml(data_id=1464, return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y)
clf = make_pipeline(StandardScaler(), LogisticRegression(random_state=0))
clf.fit(X_train, y_train)
#PrecisionRecallDisplay来可视化PR曲线
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import PrecisionRecallDisplay
prec, recall, _ = precision_recall_curve(y_test, y_score,
pos_label=clf.classes_[1])
pr_display = PrecisionRecallDisplay(precision=prec, recall=recall).plot()
参考:RocCurveDisplay
参考:受试者工作特征曲线 (receiver operating characteristic curve,简称ROC曲线)
以上是关于python使用sklearn的PrecisionRecallDisplay来可视化PR曲线的主要内容,如果未能解决你的问题,请参考以下文章
使用具有不同分类器的 sklearn precision_recall_curve 函数
sklearn 如何计算average_precision_score?
sklearn报错解决方案UndefinedMetricWarning: Precision is ill-defined and being set to 0.0
sklearn报错解决方案UndefinedMetricWarning: Precision is ill-defined and being set to 0.0