-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMFC.py
More file actions
35 lines (29 loc) · 963 Bytes
/
MFC.py
File metadata and controls
35 lines (29 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Uses Most Frequent Class Label to obtain accuracy baseline
Authors: Kenny, Raymond, Rick
Date: 5/1/2019
"""
from sklearn.metrics import confusion_matrix, accuracy_score
from collections import Counter
def evaluate(trainy, yTrue):
"""
Purpose - calculates accuracy and prints confusion matrix
Param - trainy - list of actual train labels
yTrue - list of actual test labels
"""
#calculates the accuracy using MFS
counterTrain = Counter(trainy)
maxCount = max(counterTrain.values())
for key in list(counterTrain.keys()):
if counterTrain[key] == maxCount:
MFS = key
counterTest = Counter(yTrue)
print("\nAccuracy using MFS")
accuracy = counterTest[MFS] / len(yTrue)
print(accuracy)
#creates the list of predicted values
yPred = [MFS] * len(yTrue)
#prints the confusion matrix
print("\nConfusion Matrix")
print(confusion_matrix(yTrue,yPred))
return accuracy