2017-08-16 150 views
1

我想繪製模型預測概率。Scikit學習 - 如何繪製概率

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

Graph

然而,我得到像上述的曲線圖。哪種有道理,但我想更好地想象概率分佈。有沒有一種方法可以做到這一點,我的實際班級是0或1,預測值介於0和1之間。

回答

0

您可以根據真實值拆分值,然後繪製兩個班級的值的兩個分支,例如以下的(至少如果你有一個numpy的陣列arr_truearr_pred這應該工作):

arr_true_0_indices = (y_test == 0.0) 
arr_true_1_indices = (y_test == 1.0) 

arr_pred_0 = prediction[arr_true_0_indices] 
arr_pred_1 = prediction[arr_true_1_indices] 

plt.hist(arr_pred_0, bins=40, label='True class 0', normed=True, histtype='step') 
plt.hist(arr_pred_1, bins=40, label='True class 1', normed=True, histtype='step') 
plt.xlabel('Network output') 
plt.ylabel('Arbitrary units/probability') 
plt.legend(loc='best') 
plt.show() 

這將導致這樣的事情:enter image description here