混淆矩阵轴的正确标记
Correct labelling of confusion matrix axis
我写了下面的代码来生成混淆矩阵
from sklearn.naive_bayes import MultinomialNB
mnb=MultinomialNB()
mnb.fit(X_train,Y_train)
sms2="REMINDER FROM O2: To get 2.50 pounds free call credit and details of great offers pls reply 2 this text with your valid name, house no and postcode"
sms="You’ve Won!"
X_test = [str (item) for item in X_test]
Y_pred = mnb.predict(vec.transform(X_test))
from sklearn.metrics import confusion_matrix
mat = confusion_matrix(Y_test, Y_pred)
print(mat)
names =[ "non-spam", "spam"]
print(names)
sns.heatmap(mat, square=True, annot=True, fmt='d', cbar=False,
xticklabels=names, yticklabels=names)
plt.xlabel('Actual [Truth]')
plt.ylabel('Predicted')
plt.show()
它生成了以下混淆矩阵:
我不确定轴是否标记正确
IE。如果x轴应该是Actual而y轴应该是predicted
或者反过来
根据 scikit=learn 文档,https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html,第一个调用参数应该是真实值,第二个调用参数应该是通过分类器的预测值。
如果是这样,那么混淆矩阵的 return 参数应该包含包含真实 类 的行,并且列应该是预测的 类.
基于此,我认为您的标签落后了。另请参阅示例 https://scikit-learn.org/stable/auto_examples/miscellaneous/plot_display_object_visualization.html#sphx-glr-auto-examples-miscellaneous-plot-display-object-visualization-py
我写了下面的代码来生成混淆矩阵
from sklearn.naive_bayes import MultinomialNB
mnb=MultinomialNB()
mnb.fit(X_train,Y_train)
sms2="REMINDER FROM O2: To get 2.50 pounds free call credit and details of great offers pls reply 2 this text with your valid name, house no and postcode"
sms="You’ve Won!"
X_test = [str (item) for item in X_test]
Y_pred = mnb.predict(vec.transform(X_test))
from sklearn.metrics import confusion_matrix
mat = confusion_matrix(Y_test, Y_pred)
print(mat)
names =[ "non-spam", "spam"]
print(names)
sns.heatmap(mat, square=True, annot=True, fmt='d', cbar=False,
xticklabels=names, yticklabels=names)
plt.xlabel('Actual [Truth]')
plt.ylabel('Predicted')
plt.show()
它生成了以下混淆矩阵:
我不确定轴是否标记正确
IE。如果x轴应该是Actual而y轴应该是predicted
或者反过来
根据 scikit=learn 文档,https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html,第一个调用参数应该是真实值,第二个调用参数应该是通过分类器的预测值。
如果是这样,那么混淆矩阵的 return 参数应该包含包含真实 类 的行,并且列应该是预测的 类.
基于此,我认为您的标签落后了。另请参阅示例 https://scikit-learn.org/stable/auto_examples/miscellaneous/plot_display_object_visualization.html#sphx-glr-auto-examples-miscellaneous-plot-display-object-visualization-py