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

import sklearn.metrics from plot_confusion_matrix

from sklearn.metrics import plot_confusion_matrix
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

PREVIOUS NEXT
Code Example
Python :: pyspark when otherwise multiple conditions 
Python :: embed discord.py 
Python :: loop append to list python 
Python :: pandas shift all columns 
Python :: add text to plot python scatter 
Python :: python get string from decimal 
Python :: how to make a minute counter in python 
Python :: python creating a dict from a string 
Python :: word generator in python 
Python :: create alinked list inb pyhton 
Python :: change variable type python 
Python :: Conversion of number string to float in django 
Python :: numpy array_equal 
Python :: pillow rgb to grayscale 
Python :: how to reboot a python script 
Python :: delete spaces in string python 
Python :: replace all missing value with mean pandas 
Python :: python get cookie from browser 
Python :: transpose array python 
Python :: python push to dataframe pandas 
Python :: read_table python 
Python :: integer to datetime python 
Python :: how to change avatar of a bot using discord.py 
Python :: increase a date in python 
Python :: sort a series pandas 
Python :: pandas read dictionary 
Python :: python sorted word frequency count 
Python :: python count multiple characters in string 
Python :: how to get user id from username discord.py 
Python :: identify total number of iframes with Selenium 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =