我有一个数据矩阵X
它是n
x 2和相应的二元标签阵列y
,说第i个人是否是赢家。我试图用散热图创建一个散点图,其中显示了图上每个点的预测概率,即赢家。这是到目前为止我的代码2d scatter matplotlib背后的热图
import matplotlib.pyplot as plt
from sklearn.externals import joblib
from sklearn.linear_model import LogisticRegression
X = joblib.load('X.pkl')
y = joblib.load('y.pkl')
lr = LogisticRegression()
lr.fit(X, y)
plt.scatter(X[y == 1, 0], X[y == 1, 1], color='r', label='winners', s=1)
plt.scatter(X[y == 0, 0], X[y == 0, 1], color='b', label='losers', s=1)
plt.legend()
# Want to add a heatmap in the background for predicted probabilities here
plt.show()
从本质上讲,我希望背景是越红,其中预测的概率很高,更蓝的地方低。我可以使用lr.predict_proba(X)[:0]
获得一组点的概率。
如何给背景着色,使得图中的每个点(x1,x2)根据其预测的获胜概率获得颜色?
有你在这[问题]阅读解决方案(http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set)?作为热图的散射可能与您想要的不一样,但这可能对您有所帮助。 –