Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

precision and recall from confusion matrix python

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) 
        
# 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() 

recall = tp / (tp + fn)       # definition of recall
precision = tp / (tp + fp)    # definition of precision
Comment

PREVIOUS NEXT
Code Example
Python :: render() in django 
Python :: how to check if value is in list python 
Python :: openpyxl read cell value 
Python :: python binary search 
Python :: break in python 
Python :: matplotlib histogram python 
Python :: df add value at first index 
Python :: Scrapping tables in an HTML file with BeautifulSoup 
Python :: create a django project 
Python :: Invalid comparison between dtype=datetime64[ns] and date filter 
Python :: pandas df represent a long column name with short name 
Python :: hungry chef solution 
Python :: serialize keras model 
Python :: assosciate keys as list to values in python 
Python :: what is += python 
Python :: df insert 
Python :: how to capitalize first letter in python in list using list comprehension 
Python :: update python 3.9 
Python :: image.open no such file or directory 
Python :: how to create a virtual environment in python 
Python :: creating an apis with python and flask 
Python :: python find string in list 
Python :: lambda en python 
Python :: python codes 
Python :: tk is not defined python 3 
Python :: print labels on confusion_matrix 
Python :: Python Tkinter RadioButton Widget 
Python :: how to append list in python 
Python :: python get last element of array 
Python :: python PyDrive service account credentials 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =