forked from sauriii98/Computational-Models-of-Motor-Imagery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun_Save_models.py
62 lines (35 loc) · 2.1 KB
/
Run_Save_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
from sklearn.naive_bayes import GaussianNB, BernoulliNB
from sklearn.metrics import classification_report,confusion_matrix
import pandas as pd
from Import_data import import_data
from c_models import classifier_model, svm_ml, dTree_ml, rforest_ml, adaBoost_ml, bagging_ml, gaussianNB_ml, \
bernoulliNB_ml, MLP_ml, QDA_ml, KNN_ml
def run_save_models(file_names):
filewise_train_reports = {"models": ['SVM','Decision_tree','rforest','AdaBoost','Bagging','gaussianNB_ml','bernoulliNB_ml','MLP_ml','QDA_ml','KNN_ml']}
filewise_test_reports = {"models": ['SVM','Decision_tree','rforest','AdaBoost','Bagging','gaussianNB_ml','bernoulliNB_ml','MLP_ml','QDA_ml','KNN_ml']}
i=0
for file in file_names:
(X_train,y_train),(x_test,y_test) = import_data(file)
reports = []
reports.append(svm_ml(X_train, y_train, x_test, y_test))
reports.append(dTree_ml(X_train, y_train, x_test, y_test))
reports.append(rforest_ml(X_train, y_train, x_test, y_test))
reports.append(adaBoost_ml(X_train, y_train, x_test, y_test))
reports.append(bagging_ml(X_train, y_train, x_test, y_test))
reports.append(gaussianNB_ml(X_train, y_train, x_test, y_test))
reports.append(bernoulliNB_ml(X_train, y_train, x_test, y_test))
reports.append(MLP_ml(X_train, y_train, x_test, y_test))
reports.append(QDA_ml(X_train, y_train, x_test, y_test))
reports.append(KNN_ml(X_train, y_train, x_test, y_test))
train_accuracy = []
test_accuracy = []
for report in reports:
train_accuracy.append(report[0])
test_accuracy.append(report[1])
filewise_train_reports[file] = train_accuracy
filewise_test_reports[file] = test_accuracy
filewise_test_reports_df = pd.DataFrame.from_dict(filewise_test_reports)
filewise_train_reports_df = pd.DataFrame.from_dict(filewise_train_reports)
filewise_test_reports_df.to_csv('Reports/file_wise_test_reports.csv')
filewise_train_reports_df.to_csv('Reports/filewise_train_reports.csv')
return filewise_train_reports_df,filewise_test_reports_df