0

私は混乱行列をプロットしています。私はScikitLearnの関数を使っています。しかし、私はカラーバーが0から1までの範囲を持たない理由を知りません。それを強制する方法はありますか?カラーバーが正規化されていない(0〜1)のはなぜですか?それを強制する方法?

import itertools 
def plot_confusion_matrix(cm, title='Confusion matrix RF', cmap=plt.cm.viridis): 
plt.imshow(cm, interpolation='nearest', cmap=cmap) 
plt.title(title) 
plt.colorbar() 
tick_marks = np.arange(len(np.unique(y))) 

plt.xticks(tick_marks, rotation=90) 
ax = plt.gca() 
ax.set_xticklabels(['s'+lab for lab in (ax.get_xticks()+1).astype(str)]) 
plt.yticks(tick_marks) 
ax.set_yticklabels(['s'+lab for lab in (ax.get_yticks()+1).astype(str)]) 

plt.tight_layout() 
plt.ylabel('True label') 
plt.xlabel('Predicted label') 




cm_imp = confusion_matrix(y_true, y_pred) 
cm_imp_normalized = cm_imp.astype('float')/cm_imp.sum(axis=1)[:, np.newaxis] 
plt.figure(figsize=(8,6)) 
plot_confusion_matrix(cm_imp_normalized) 
plt.show() 
print("") 
print("") 

enter image description here

答えて

1

あなたはimshowvmin, vmax引数を使用して色の範囲を設定することができます。

plt.imshow(data, cmap=cmap, vmin=0, vmax=1) 
関連する問題