"confusion matrix" Code Answer's
You're definitely familiar with the best coding language Python that developers use to develop their projects and they get all their queries like "confusion matrix" answered properly. Developers are finding an appropriate answer about confusion matrix related to the Python coding language. By visiting this online portal developers get answers concerning Python codes question like confusion matrix. Enter your desired code related query in the search bar and get every piece of information about Python code related question on confusion matrix.
confusion matrix python
By definition, entry i,j in a confusion matrix is the number of
observations actually in group i, but predicted to be in group j.
Scikit-Learn provides a confusion_matrix function:
from sklearn.metrics import confusion_matrix
y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]
confusion_matrix(y_actu, y_pred)
# Output
# array([[3, 0, 0],
# [0, 1, 2],
# [2, 1, 3]], dtype=int64)
Source: scikit-learn.org
plot confusion matrix function deep learning
def plot_confusion_matrix(cm, classes,
normalize=False,
title='Confusion matrix',
cmap=plt.cm.Blues):
"""
This function prints and plots the confusion matrix.
Normalization can be applied by setting `normalize=True`.
"""
plt.imshow(cm, interpolation='nearest', cmap=cmap)
plt.title(title)
plt.colorbar()
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=45)
plt.yticks(tick_marks, classes)
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
print("Normalized confusion matrix")
else:
print('Confusion matrix, without normalization')
print(cm)
thresh = cm.max() / 2.
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
plt.text(j, i, cm[i, j],
horizontalalignment="center",
color="white" if cm[i, j] > thresh else "black")
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
Source: deeplizard.com
All those coders who are working on the Python based application and are stuck on confusion matrix can get a collection of related answers to their query. Programmers need to enter their query on confusion matrix related to Python code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about confusion matrix for the programmers working on Python code while coding their module. Coders are also allowed to rectify already present answers of confusion matrix while working on the Python language code. Developers can add up suggestions if they deem fit any other answer relating to "confusion matrix". Visit this developer's friendly online web community, CodeProZone, and get your queries like confusion matrix resolved professionally and stay updated to the latest Python updates.