-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontroller.py
119 lines (99 loc) · 3.48 KB
/
controller.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import numpy as np
from pandas import read_csv
from custom import custom_logistic_regression_classification, custom_naive_bayes_classification, \
custom_knn_classification
from inbuilt import naivebayes_classification, logistic_regression_classification, knn_classification
from visualize_data import Visualize
"""
Reads the input csv file and makes a pd.DataFrame object to be used to call all the prediction functions
inside the Custom and SKLearn models.
After prediction, accuracies are returned and comparision is done.
"""
df = read_csv("./dataset/test.csv")
X = df.iloc[:, :-1]
y = df['class']
knn = []
nb = []
lr = []
class Controller:
def __init__(self, App):
"""
Controller to control the UI interactions and communication to set data and call functions on button
clicks
Parameters
----------
App : QWidget
to call UI functions to set text on labels
"""
self.app = App
def plot_dataframe(self):
"""
Calling the Visualize.visualize() function to plot the data frame
"""
print("Plotting")
visualizer = Visualize(df)
visualizer.visualize()
return
def callKNNs(self):
"""
Calling both implementations of SKLearn and Custom KNN
"""
knn_classification.controller_predict(self, X, y)
custom_knn_classification.controller_predict(self, X.values, y.values)
def callNBs(self):
"""
Calling both implementations of SKLearn and Custom NB
"""
naivebayes_classification.controller_predict(self, X, y)
custom_naive_bayes_classification.controller_predict(self, X, y)
def callLRs(self):
"""
Calling both implementations of SKLearn and Custom LR
"""
logistic_regression_classification.controller_predict(self, X, y)
custom_logistic_regression_classification.controller_predict(self, X.values, y.values)
def setKNNInbuilt(self, text):
"""
Setting the accuracies to the UI using the App object
"""
knn.append(text)
self.app.knnInbuiltLabel.setText("Sklearn : " + str(text))
def setKNNCustom(self, text):
"""
Setting the accuracies to the UI using the App object
"""
knn.append(text)
self.app.knnCustomLabel.setText("Custom : " + str(text))
def setNBInbuilt(self, text):
"""
Setting the accuracies to the UI using the App object
"""
nb.append(text)
self.app.nbInbuiltLabel.setText("Sklearn : " + str(text))
def setNBCustom(self, text):
"""
Setting the accuracies to the UI using the App object
"""
nb.append(text)
self.app.nbCustomLabel.setText("Custom : " + str(text))
def setLRInbuilt(self, text):
"""
Setting the accuracies to the UI using the App object
"""
lr.append(text)
self.app.lrInbuiltLabel.setText("Sklearn : " + str(text))
def setLRCustom(self, text):
"""
Setting the accuracies to the UI using the App object
"""
lr.append(text)
self.app.lrCustomLabel.setText("Custom : " + str(text))
def compare(self):
"""
Setting the comparison of all the algorithms to the UI using the App object
"""
k = np.mean(knn)
n = np.mean(nb)
l = np.mean(lr)
dict = {"KNN": k, "NB": n, "LR": l}
return sorted(dict.items(), key=lambda x: x[1], reverse=True)