diff --git a/evaluate_model.py b/evaluate_model.py index 8abd2e9fc70578d30e11f7c54162a45521d1fe6e..f258ccd2d45248c3e67e6846f9f18cbc9c66aebc 100644 --- a/evaluate_model.py +++ b/evaluate_model.py @@ -57,14 +57,3 @@ def evaluate_model(clf, X_test, y_test, y_pred, valid_y, classes, classesName, p plt.savefig(pathSave) return df, accuracy, weighted_avg -import seaborn as sns -import matplotlib.pyplot as plt -from sklearn.metrics import confusion_matrix - - -#y_true = [2, 0, 2, 2, 0, 1] -#y_pred = [0, 0, 2, 2, 0, 2] -#cf_matrix = confusion_matrix(y_true, y_pred) -#sns.heatmap(cf_matrix, annot=True) -#import matplotlib.pyplot as plt -#plt.show() diff --git a/experimentsClassicClassifiers.py b/experimentsClassicClassifiers.py index c6a9f72df02bcf23e2b34c57b2629128f3581b03..3c6991549d1b2464c614f22725e3892c66ac7eb8 100644 --- a/experimentsClassicClassifiers.py +++ b/experimentsClassicClassifiers.py @@ -96,44 +96,27 @@ for columnInput in [columnText, 'firstParagraph']: grid_param_name, grid_param = tmp_grid_params print(clf_name, clf, grid_param_name, grid_param) model_file_name = columnInput + '_' +feature_technique_name + '_' + clf_name+ str(minOfInstancePerClass) + '_' + str(maxOfInstancePerClass) +".pkl" - if clf_name == 'bayes' : - if feature_technique_name == 'doc2vec': - continue - else: - t_begin = time.time() - # if model exist - if os.path.isfile(os.path.join('./model', model_file_name)): - with open(model_file_name, 'rb') as file: - clf = pickle.load(file) - else: - #if model not exists we save - with open(Pkl_Filename, 'wb') as file: - clf.fit(train_x, train_y) - pickle.dump(clf, file) - - t_end =time.time() - training_time = t_end - t_begin - - y_pred = clf.predict(test_x) - - else : - + + if clf_name != 'bayes' : clf = GridSearchCV(clf, grid_param, refit = True, verbose = 3) - t_begin = time.time() + else if feature_technique_name == 'doc2vec': + continue + + t_begin = time.time() - if os.path.isfile(os.path.join('./model', model_file_name)): - with open(model_file_name, 'rb') as file: - clf = pickle.load(file) - else: - with open(Pkl_Filename, 'wb') as file: - clf.fit(train_x, train_y) - pickle.dump(clf, file) + if os.path.isfile(os.path.join('./model', model_file_name)): + with open(model_file_name, 'rb') as file: + clf = pickle.load(file) + else: + with open(Pkl_Filename, 'wb') as file: + clf.fit(train_x, train_y) + pickle.dump(clf, file) - t_end =time.time() + t_end =time.time() - training_time = t_end - t_begin + training_time = t_end - t_begin - y_pred = clf.predict(test_x) + y_pred = clf.predict(test_x) #evaluate model file_name_report = columnInput + '_' +feature_technique_name + '_' + clf_name