def evaluate(self, gold_labels, pred_labels, target_names): overall_accuracy = accuracy_score(gold_labels, pred_labels) #class_report = classification_report(gold_labels, pred_labels, target_names=target_names) precision = metrics.precision_score(gold_labels, pred_labels) recall = metrics.recall_score(gold_labels, pred_labels) f1_score = metrics.f1_score(gold_labels, pred_labels) return overall_accuracy, precision, recall, f1_score
def SVM(X_train,y_train,X_test,y_test): '''fit a SVM model to the data ''' t0 = time() # normalize min_max_scaler = MinMaxScaler() X_train = min_max_scaler.fit_transform(X_train) X_test = min_max_scaler.fit_transform(X_test) model = SVC(kernel = "rbf") model.fit(X_train, y_train) print ("training time:", round(time()-t0, 3), "s") # make predictions t0 = time() expected = y_test predicted = model.predict(X_test) print ("predicting time:", round(time()-t0, 3), "s") # summarize the fit of the model score = metrics.accuracy_score(expected, predicted) print(score) print(metrics.recall_score(expected,predicted)) return model, score
def DTree(X_train, y_train, X_test, y_test): model = tree.DecisionTreeClassifier(min_samples_split=40) t0 = time() model.fit(X_train, y_train) print("training time:", round(time() - t0, 3), "s") t0 = time() expected = y_test predicted = model.predict(X_test) print("predicting time:", round(time() - t0, 3), "s") # summarize the fit of the model score = metrics.accuracy_score(expected, predicted) print(score) print(metrics.recall_score(expected, predicted)) return model, score
def SVM(X_train, y_train, X_test, y_test): # fit a SVM model to the data t0 = time() model = SVC(kernel="linear") model.fit(X_train, y_train) print("training time:", round(time() - t0, 3), "s") #print(model) # make predictions t0 = time() expected = y_test predicted = model.predict(X_test) print("predicting time:", round(time() - t0, 3), "s") # summarize the fit of the model score = metrics.accuracy_score(expected, predicted) print(score) print(metrics.recall_score(expected, predicted)) return model, score