def plot_arcma(): arcma = ARCMA_Model() p = 15 arcma_threshold_classification = 0.65 relevant_features = s.load_var( "arcma_relevant_features_best_window{}relevant_features_{}.pkl".format( slash, p)) y = s.load_var("arcma_relevant_features_best_window{}y_{}.pkl".format( slash, p)) y = pd.DataFrame(y, columns=[arcma.label_tag]) #Remove Activit with label 0, not discribed in arcma doc #invalid_indexes = list(y[y["activity"]==0].index) #y_new = y.drop(labels=invalid_indexes) #relevant_features_new = relevant_features.drop(labels=invalid_indexes) #Translate Arcma Labels y[y["activity"] == 0] = "Indefinida" y[y["activity"] == 1] = "working_at_computer" y[y["activity"] == 2] = "standing_up_walking_going_updown_stairs" y[y["activity"] == 3] = "standing" y[y["activity"] == 4] = "walking" y[y["activity"] == 5] = "going_updown_stairs" y[y["activity"] == 6] = "walking_and_talking_with_someone." y[y["activity"] == 7] = "talking_while_standing" balanced_data = balance_data.balance_data(relevant_features, y, threshold_balance_data) plot_confusion_matrix(arcma, balanced_data[0], balanced_data[1], arcma_threshold_classification)
# -*- coding: utf-8 -*- # IMPORTS # from utils.debug import Debug from models.arcma_model import ARCMA_Model from tsfresh import extract_relevant_features from pre_processing.processing_db_files import Processing_DB_Files from utils.project import Project, slash from scripts.save_workspace import save #===INITIALIZATION===# Debug.DEBUG = 0 arcma = ARCMA_Model() processing = Processing_DB_Files() project = Project() s = save() #window = 26 # Janela Fixa window = 50 # Melhor Janela persons = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] for p in persons: data = arcma.load_training_data_by_people(p) print("Slicing Window....") data_tsfresh, y = arcma.slice_by_window_tsfresh(data, window) y.index += 1 del data_tsfresh["activity"] classes_counts = y.value_counts() if len(classes_counts) > 1: relevant_features = extract_relevant_features(data_tsfresh, y,
from sklearn.ensemble import ExtraTreesClassifier # Extra Trees from sklearn.naive_bayes import GaussianNB #Naive Bayes from sklearn import svm #SVM from sklearn.neural_network import MLPClassifier #multi-layer percept import pandas as pd from sklearn.model_selection import train_test_split from pre_processing.get_accuracy import Get_Accuracy from scripts.save_workspace import save import numpy as np from pre_processing.balance_data import BalanceData import statistics as st #===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"])
#Round 01 models.append({ "model_name": "hmp", "model": HMP_Model(), "persons": hmp_persons, "window": 16 }) models.append({ "model_name": "umafall", "model": UMAFALL_Model(), "persons": umafall_persons, "window": 10 }) models.append({ "model_name": "arcma", "model": ARCMA_Model(), "persons": arcma_persons, "window": 26 }) #Round 02 #models.append({"model_name":"hmp", "model":HMP_Model(), "persons":hmp_persons, "window":90}) #models.append({"model_name":"umafall", "model":UMAFALL_Model(), "persons":umafall_persons, "window":10}) #models.append({"model_name":"arcma", "model":ARCMA_Model(), "persons":arcma_persons, "window":40}) #tuple from MPL t_aux = [] for i in range(0, 500): t_aux.append(500) t = tuple(t_aux) #### classifiers = {
# -*- coding: utf-8 -*- from models.arcma_model import ARCMA_Model from models.hmp_model import HMP_Model from models.umafall_model import UMAFALL_Model #ARCMA arcma = ARCMA_Model() arcma.load_training_data_by_window_by_people(1, 36) sample_arcma = arcma.training[0] sample_arcma_to_plot = sample_arcma.drop("activity", 1) sample_arcma_to_plot.plot(subplots=True, legend=True, figsize=(20, 10)) #HMP hmp = HMP_Model() hmp.load_training_data_by_window_by_people("f1", 36) sample_hmp = hmp.training[0] sample_hmp_to_plot = sample_hmp.drop("activity", 1) sample_hmp_to_plot.plot(subplots=True, legend=True, figsize=(20, 10)) #UMAFALL umafall = UMAFALL_Model() umafall.load_training_data_by_window_by_people( "1", 10, additional_where="and sensor=2 and body=3") sample_umafall = umafall.training[0] sample_umafall_to_plot = sample_umafall.drop("activity", 1) sample_umafall_to_plot.plot(subplots=True, legend=True, figsize=(20, 10))
#===INIT BASES===# hmp_persons = ["f1", "m1", "m2", "f2", "m3", "f3", "m4", "f4"] # at least 5 activities #umafall_persons = [1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17] umafall_persons = [8,10,11,12,13,14,15,16,17] arcma_persons = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] models = [] #Round 01 #models.append({"model_name":"hmp", "model":HMP_Model(), "persons":hmp_persons, "window":16, "where":""}) #models.append({"model_name":"umafall", "model":UMAFALL_Model(), "persons":umafall_persons, "window":10, "where": "and body=2 and sensor=2"}) #MAGNETOMETER in WAIST #models.append({"model_name":"arcma", "model":ARCMA_Model(), "persons":arcma_persons, "window":26, "where":""}) #Round 02 models.append({"model_name":"hmp", "model":HMP_Model(), "persons":hmp_persons, "window":90, "where":""}) #models.append({"model_name":"umafall", "model":UMAFALL_Model(), "persons":umafall_persons, "window":10, "where": "and body=2 and sensor=2"}) #MAGNETOMETER in WAIST models.append({"model_name":"arcma", "model":ARCMA_Model(), "persons":arcma_persons, "window":40, "where":""}) for model in models: for p in model["persons"]: try: data = model['model'].load_training_data_by_people(p, additional_where = model['where']) print("Slicing Window....") data_tsfresh, y = model['model'].slice_by_window_tsfresh(data, model["window"]) y.index += 1 del data_tsfresh["activity"] classes_counts = y.value_counts() if len(classes_counts) > 1: relevant_features = extract_relevant_features(data_tsfresh, y, column_id='id', column_sort='time') s.save_var(relevant_features, "new_features{}{}_relevant_features_window_{}{}relevant_features_{}.pkl".format(slash, model['model_name'], model['window'], slash, p)) s.save_var(y, "new_features{}{}_relevant_features_window_{}{}y_{}.pkl".format(slash, model['model_name'], model['window'], slash, p))