def __init__(self, model: Model, clf): self.model = model self.get_accuracy = Get_Accuracy() self.processing = Processing_DB_Files() self.clf = clf super().__init__()
#===INITIALIZATION===# Debug.DEBUG = 0 arcma = ARCMA_Model() processing = Processing_DB_Files() project = Project() #tuple from MPL t_aux = [] for i in range(0,500): t_aux.append(500) t = tuple(t_aux) #### classifiers = {"MPL": MLPClassifier(random_state=1, solver="adam", activation="relu", max_iter=100000, alpha=1e-5, hidden_layer_sizes=t), "Extratrees": ExtraTreesClassifier(n_estimators = 1000, random_state=1), "Knn":KNeighborsClassifier(n_neighbors=5), "Naive Bayes":GaussianNB(), "RandomForest":RandomForestClassifier(n_estimators = 1000, random_state=1), "Decision Tree":tree.DecisionTreeClassifier(random_state=1), "SVM":svm.SVC(probability=True, random_state=1)} persons = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] get_accuracy = Get_Accuracy() balance_data = BalanceData() threshold_balance_data = 40 #Select the best classifier accuracy_mean = pd.DataFrame(columns=["Classifier", "Accuracy"]) project.log("=====================ARCMA_SELECT_BEST_ALGORITHM=====================", file="arcma_best_algorithm.log") for c in classifiers: print(c) person_accuracies = [] person_f_score = [] person_precision = [] person_recall = [] times_to_predict = [] for p in persons: s = save() try:
import pandas as pd from pre_processing.processing_db_files import Processing_DB_Files from utils.project import Project, slash from scripts.save_workspace import save from pre_processing.get_accuracy import Get_Accuracy from sklearn.model_selection import StratifiedKFold from pre_processing.balance_data import BalanceData import numpy as np #===INITIALIZATION===# Debug.DEBUG = 0 hmp = HMP_Model() processing = Processing_DB_Files() project = Project() extra_trees = ExtraTreesClassifier(n_estimators=1000, random_state=0) get_accuracy = Get_Accuracy() balance_data = BalanceData() threshold_balance_data = 40 #===LOAD FEATURES===# #Interate threshold to find de best value# persons = [ "f1", "m1", "m2", "f2", "m3", "f3", "m4", "m5", "m6", "m7", "f4", "m8", "m9", "f5", "m10", "m11" ] accuracy_by_person = pd.DataFrame() threshold = 0.65 project.log( "=========== HMP StratifiedKFold Accuracy, Thresold = {}===========". format(threshold),
hidden_layer_sizes=t), "Extratrees": ExtraTreesClassifier(n_estimators=1000, random_state=1), "Knn": KNeighborsClassifier(n_neighbors=5), "Naive Bayes": GaussianNB(), "RandomForest": RandomForestClassifier(n_estimators=1000, random_state=1), "Decision Tree": tree.DecisionTreeClassifier(random_state=1), "SVM": svm.SVC(probability=True, random_state=1) } get_accuracy = Get_Accuracy() balance_data = BalanceData() threshold_balance_data = 40 #Select the best classifier for model in models: print(model['model_name']) persons = model['persons'] accuracy_mean = pd.DataFrame(columns=[ "Classifier", "Accuracy", "Precision", "Recall", "F-Score", "Time" ]) print("====================={}_SELECT_BEST_ALGORITHM=====================". format(model['model_name'])) for c in classifiers: print(c) person_accuracies = [] person_f_score = []
from sklearn.ensemble import ExtraTreesClassifier # Extra Trees from models.hmp_model import HMP_Model import pandas as pd from sklearn.model_selection import train_test_split from pre_processing.processing_db_files import Processing_DB_Files from utils.project import Project from scripts.save_workspace import save from pre_processing.get_accuracy import Get_Accuracy #===INITIALIZATION===# Debug.DEBUG = 0 hmp = HMP_Model() processing = Processing_DB_Files() project = Project() extra_trees = ExtraTreesClassifier(n_estimators = 10000, random_state=0) get_accuracy = Get_Accuracy() #===LOAD FEATURES===# #Interate threshold to find de best value# s = save() relevant_features = s.load_var("hmp_relevant_features\\relevant_features_f1.pkl") y = s.load_var("hmp_relevant_features\\y_f1.pkl") y = pd.DataFrame(y, columns=[hmp.label_tag]) X_train, X_test, y_train, y_test = train_test_split(relevant_features, y, test_size=0.2, random_state=42) data = {} data["f1"] = {} data["f1"]["training"] = {} data["f1"]["training"]["training_features"] = X_train data["f1"]["training"]["training_labels"] = y_train
class Base_Classification(object): def __init__(self, model: Model, clf): self.model = model self.get_accuracy = Get_Accuracy() self.processing = Processing_DB_Files() self.clf = clf super().__init__() #Finding the best window to improve the accuracy def find_best_window(self, interval, list_people): accuracies = [] for w in interval: Debug.print_debug("WINDOWS SIZE: {}".format(w)) data_all_people = self.model.load_training_data_from_list_people( w, list_people) features_all_people = self.processing.calculating_features_to_each_person( data_all_people, self.model) accuracies_dict = self.get_accuracy.simple_accuracy_mean_to_each_person( features_all_people, self.model, self.clf) accuracy_mean = mean(accuracies_dict.values()) accuracies.append({'window': w, 'accuracy': accuracy_mean}) return accuracies def predict_for_all_people_with_proba(self, window, threshold): data_all_people = self.model.load_training_data_from_all_people(window) features_all_people = self.processing.calculating_features_to_each_person( data_all_people, self.model) accuracies_proba = self.get_accuracy.simple_accuracy_mean_to_each_person_with_proba( features_all_people, self.model, self.clf, threshold) accuracies = self.get_accuracy.simple_accuracy_mean_to_each_person( features_all_people, self.model, self.clf) return accuracies, accuracies_proba def predict_for_list_people_with_proba(self, window, list_people, threshold): data_list_people = self.model.load_training_data_from_list_people( window, list_people) features_all_people = self.processing.calculating_features_to_each_person( data_list_people, self.model) accuracies_proba = self.get_accuracy.simple_accuracy_mean_to_each_person_with_proba( features_all_people, self.model, self.clf, threshold) accuracies = self.get_accuracy.simple_accuracy_mean_to_each_person( features_all_people, self.model, self.clf) return accuracies, accuracies_proba def predict_outliers_for_list_people_with_proba(self, window, list_people, activity, threshold, remove_outliers=0): data_list_people = self.model.load_training_data_from_list_people( window, list_people, remove_outliers) features_all_people = self.processing.calculating_features_to_each_person( data_list_people, self.model) #return self.get_accuracy.simple_accuracy_outlier_activity(features_all_people, self.model, self.clf, activity,threshold) return self.get_accuracy.get_outliers_confused_with_activities( features_all_people, self.model, self.clf, threshold) training, training_labels, test, test_labels, outlier, outlier_labels = self.get_accuracy.simple_accuracy_outlier_activity( features_all_people, self.model, self.clf, activity, threshold)
from sklearn.ensemble import ExtraTreesClassifier # Extra Trees import pandas as pd from sklearn.model_selection import train_test_split from pre_processing.get_accuracy import Get_Accuracy import numpy as np from tsfresh import extract_relevant_features import time from pre_processing.balance_data import BalanceData #===INITIALIZATION===# Debug.DEBUG = 0 arcma = ARCMA_Model() processing = Processing_DB_Files() project = Project() persons = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] get_accuracy = Get_Accuracy() balance_data = BalanceData() threshold_balance_data = 40 #Select de best windows t = time.time() best_model = ExtraTreesClassifier(n_estimators = 1000, random_state=0) w_accuracies = pd.DataFrame(columns=["window", "accurary"]) p = 15 # pessoa com mais registros project.log("=====================ARCMA_SELECT_BEST_WINDOWS=====================", file="arcma_log_best_window.log") for w in range(20,110,10): print("Load data with window len = {}".format(w)) data = arcma.load_training_data_by_people(p) print("Slicing Window....") data_tsfresh, y = arcma.slice_by_window_tsfresh(data, w) y.index += 1