forked from sauriii98/Computational-Models-of-Motor-Imagery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_models.py
74 lines (49 loc) · 2.47 KB
/
c_models.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
from sklearn import svm
from sklearn import tree
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.naive_bayes import BernoulliNB
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
def classifier_model(clf, X_train, y_train, X_test, y_test):
clf.fit(X_train, y_train)
train_acc = clf.score(X_train, y_train)
test_acc = clf.score(X_test, y_test)
predicted_test = clf.predict(X_test)
confusion=confusion_matrix(y_test, predicted_test)
report = classification_report(y_test, predicted_test)
return train_acc, test_acc, predicted_test, confusion, report
def svm_ml(X_train, y_train, X_test, y_test):
clf = svm.SVC(kernel='rbf', max_iter=31)
return classifier_model(clf, X_train, y_train, X_test, y_test)
def dTree_ml(X_train, y_train, X_test, y_test):
clf = tree.DecisionTreeClassifier(max_depth=5)
return classifier_model(clf, X_train, y_train, X_test, y_test)
def rforest_ml(X_train, y_train, X_test, y_test):
clf = RandomForestClassifier()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def adaBoost_ml(X_train, y_train, X_test, y_test):
clf = AdaBoostClassifier(n_estimators=100, random_state=0)
return classifier_model(clf, X_train, y_train, X_test, y_test)
def bagging_ml(X_train, y_train, X_test, y_test):
clf = BaggingClassifier()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def gaussianNB_ml(X_train, y_train, X_test, y_test):
clf = GaussianNB()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def bernoulliNB_ml(X_train, y_train, X_test, y_test):
clf = BernoulliNB()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def MLP_ml(X_train, y_train, X_test, y_test):
clf = MLPClassifier()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def QDA_ml(X_train, y_train, X_test, y_test):
clf = QuadraticDiscriminantAnalysis()
return classifier_model(clf, X_train, y_train, X_test, y_test)
def KNN_ml(X_train, y_train, X_test, y_test):
clf = KNeighborsClassifier(3)
return classifier_model(clf, X_train, y_train, X_test, y_test)