0
私はあなたが以下に示す混乱マトリクスをプロットしました。 ラベルを変更したいと思います。 s1 - > s37の代わりに。私は欲しい:s1 - > s21、I1 - > I16混乱行列に2種類のティックラベルを入れるにはどうすればいいですか?
import itertools
def plot_confusion_matrix(cm, title='Confusion matrix RF', cmap=plt.cm.viridis):
plt.imshow(cm, interpolation='nearest', cmap=cmap) #Display an image on the axes
plt.title(title)
plt.colorbar() #the vertical bar at the right side
#tick_marks = np.arange(len(np.unique(y_oos))) #has the length of the # of classes (array)
tick_marks = np.arange(37) #I KNOW IT IS HERE!!!
plt.xticks(tick_marks, rotation=90) #to Rotate the names
ax = plt.gca()
ax.set_xticklabels(['s'+lab for lab in (ax.get_xticks()+1).astype(str)]) # AND ALSO HERE!!!
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')
んが、そのことがありません。そのxticklabelsとyticklabelsで。必要なラベルを付けてカスタムリストを渡します。 –