gpt4 book ai didi

python - Scikit Learn - 如何绘制概率

转载 作者:太空宇宙 更新时间:2023-11-04 00:31:27 24 4
gpt4 key购买 nike

我想绘制模型预测概率。

plt.scatter(y_test, prediction[:,0])
plt.xlabel("True Values")
plt.ylabel("Predictions")
plt.show()

Graph

但是,我得到了一个像上面这样的图表。哪种有意义,但我想更好地可视化概率分布。有没有一种方法可以让我的实际类别为 0 或 1 并且预测介于 0 和 1 之间。

最佳答案

预测概率可用于可视化模型性能。真正的标签可以用颜色来表示。

试试这个例子:

from sklearn.datasets import make_classification
import matplotlib.pyplot as plt

X, y = make_classification(n_samples=1000, n_features=4,
n_informative=2, n_redundant=0,
random_state=1, shuffle=False)
from sklearn.linear_model import LogisticRegression

lr=LogisticRegression(random_state=0, solver='lbfgs', max_iter=10)
lr.fit(X, y)

prediction=lr.predict_proba(X)[:,1]

plt.figure(figsize=(15,7))
plt.hist(prediction[y==0], bins=50, label='Negatives')
plt.hist(prediction[y==1], bins=50, label='Positives', alpha=0.7, color='r')
plt.xlabel('Probability of being Positive Class', fontsize=25)
plt.ylabel('Number of records in each bucket', fontsize=25)
plt.legend(fontsize=15)
plt.tick_params(axis='both', labelsize=25, pad=5)
plt.show()

enter image description here

关于python - Scikit Learn - 如何绘制概率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45715018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com