Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sklearn plot confusion matrix

import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, plot_confusion_matrix

clf = # define your classifier (Decision Tree, Random Forest etc.)
clf.fit(X, y) # fit your classifier

# make predictions with your classifier
y_pred = clf.predict(X)         
# optional: get true negative (tn), false positive (fp)
# false negative (fn) and true positive (tp) from confusion matrix
M = confusion_matrix(y, y_pred)
tn, fp, fn, tp = M.ravel() 
# plotting the confusion matrix
plot_confusion_matrix(clf, X, y)
plt.show()
Comment

python plot_confusion_matrix

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(test_Y, predictions_dt)
cm
# after creating the confusion matrix, for better understaning plot the cm.
import seaborn as sn
plt.figure(figsize = (10,8))
# were 'cmap' is used to set the accent colour
sn.heatmap(cm, annot=True, cmap= 'flare',  fmt='d', cbar=True)
plt.xlabel('Predicted_Label')
plt.ylabel('Truth_Label')
plt.title('Confusion Matrix - Decision Tree')
Comment

sklearn plot confusion matrix

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import  plot_confusion_matrix
clf = LogisticRegression()
clf.fit(X_train,y_train)
disp = plot_confusion_matrix(clf,X_test,y_test,cmap="Blues",values_format='.3g')
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
Comment

plot confusion matrix scikit learn

from sklearn import metrics
metrics.ConfusionMatrixDisplay.from_predictions(true_y, predicted_y).plot()
Comment

how to plot confusion matrix

import seaborn as sns
from sklearn.metrics import confusion_matrix
# y_test  : actual labels or target
# y_preds : predicted labels or target
sns.heatmap(confusion_matrix(y_test, y_preds),annot=True);
Comment

how to get confusion matrix in python

from sklearn.metrics import confusion_matrix
conf_mat = confusion_matrix(y_test, y_pred)
Comment

plotting confusion matrix

from sklearn.metrics import confusion_matrix
matrix_confusion = confusion_matrix(y_test, y_pred)
sns.heatmap(matrix_confusion, square=True, annot=True, cmap='Blues', fmt='d', cbar=False
Comment

autoplot confusion matrix

autoplot(confusion)
Comment

PREVIOUS NEXT
Code Example
Python :: ssl django nginx 
Python :: strip first occurence of substring python 
Python :: get length of pandas 
Python :: pyspark dropna in one column 
Python :: python parallel processing for loop 
Python :: max of three numbers in python 
Python :: get context data django 
Python :: how to detect when a key is pressed in pygame 
Python :: count item in list python 
Python :: python how to make notepad 
Python :: selenium firefox webdriver 
Python :: best python ide for ubuntu 
Python :: split string in python 
Python :: know datatype of pandas 
Python :: root mean square python 
Python :: print column in pandas 
Python :: ravel python 
Python :: count characters in string python 
Python :: Write a Python program to count the number of lines in a text file. 
Python :: python foreach list 
Python :: what does int do in python 
Python :: odd or even python 
Python :: ln in python 
Python :: python 3 f string float format 
Python :: sciket learn imputer code 
Python :: gematria python 
Python :: how to iterate through a list in python 
Python :: how to install packages inside thepython script 
Python :: django regexvalidator example 
Python :: python datetime object 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =