Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Calculate Precision & Recall & F-Measure & Accuracy with Confusion Matrix (TP, TN, FP, FN)

License

NotificationsYou must be signed in to change notification settings

semnan-university-ai/confusion-matrix-classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Calculate Precision & Recall & F-Measure & Accuracy with Confusion Matrix (TP, TN, FP, FN)

Confusion Matrix ::

Positive PredictionNegative Prediction
Positive ClassTrue Positive (TP)False Negative (FN)
Negative ClassFalse Positive (FP)True Negative (TN)

Precision quantifies Formula :

Precision = TruePositives / (TruePositives + FalsePositives)Precision = TP / ( TP + FP )

Recall quantifies Formula :

Recall = TruePositives / (TruePositives + FalseNegatives)Recall = TP / ( TP + FN )

F-Measure quantifies Formula :

F-Measure = (2 * Precision * Recall) / (Precision + Recall)

Accuracy quantifies Formula :

accuracy = (TruePositives + TrueNegative) / (TruePositives + FalsePositive + False Negative + TrueNegative)accuracy = (TP + TN) / (TP + FP + FN + TN)

Code (python class) :

class confusionMatrixClassification:# Author : Amir Shokri# Email : amirsh.nll@gmail.com# Date : Dec 2021# git : https://github.com/amirshnll/confusion-matrix-classification/def __init__(self):self.tp = 0.0self.tf = 0.0self.fp = 0.0self.fn = 0.0def setTP(self, tp):self.tp = float(tp)def getTP(self):return float(self.tp)def setTF(self, tf):self.tf = float(tf)def getTF(self):return float(self.tf)def setFP(self, fp):self.fp = float(fp)def getFP(self):return float(self.fp)def setFN(self, fn):self.fn = float(fn)def getFN(self):return float(self.fn)def precision(self):try:return ( self.getTP() + self.getTF() ) / ( self.getTP() + self.getTF() + self.getFP() + self.getFN() )except:return -1 # errordef accuracy(self):try:return self.getTP() / ( self.getTP() + self.getFP() )except:return -1 # errordef recall(self):try:return self.getTP() / ( self.getTP() + self.getFN() )except:return -1 # errordef fmeasure(self):precision_value = self.precision()recall_value = self.recall()if precision_value == -1 or recall_value == -1:return -1 # errortry:return ( 2 * precision_value ) / ( precision_value + recall_value )except:return -1 # error

Code (usage) :

cmc = confusionMatrixClassification()cmc.setTP(90)cmc.setFP(30)cmc.setFN(10)print("Accuracy : " + str(cmc.accuracy())) # 0.75print("Precision : " + str(cmc.precision())) # 0.6923076923076923print("Recall : " + str(cmc.recall())) # 0.9print("F-Measure : " + str(cmc.fmeasure())) # 0.8695652173913042

About

Calculate Precision & Recall & F-Measure & Accuracy with Confusion Matrix (TP, TN, FP, FN)

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp