def __init__(self, model: Model, clf): self.model = model self.get_accuracy = Get_Accuracy() self.processing = Processing_DB_Files() self.clf = clf super().__init__()
# -*- 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,
def outlier_prepare(self, model:Model, people:str, windows_size:int, activity_outlier:str): processing = Processing_DB_Files() model.load_training_data_by_window_by_people(people, windows_size) training, training_labels, test, test_labels = processing.calculating_features(model) return self.generate_outliers(training, training_labels, test, test_labels, activity_outlier)
from tsfresh import extract_features from tsfresh import extract_relevant_features from tsfresh.utilities.dataframe_functions import impute import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from pre_processing.processing_db_files import Processing_DB_Files import itertools from sklearn.metrics import accuracy_score from utils.project import Project import time #===INITIALIZATION===# Debug.DEBUG = 0 hmp = HMP_Model() processing = Processing_DB_Files() project = Project() extra_trees = ExtraTreesClassifier(n_estimators=1000, max_depth=1000, random_state=0) #Good performer base_classification = Base_Classification(hmp, extra_trees) _, _, _ = base_classification.predict_outliers_for_list_people_with_proba( 36, ["f1", "m1", "m2"], "eat_soup", 0.55, remove_outliers=0.05) #===Extract TsFresh Features===# dataframe_1 = hmp.data_with_window["f1"]["training"] dataframe_2 = pd.DataFrame() labels = [] id = 1 for d in dataframe_1: if len(np.unique(d[hmp.label_tag])) < 2:
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)
# -*- coding: utf-8 -*- from utils.debug import Debug from models.hmp_model import HMP_Model from pre_processing.processing_db_files import Processing_DB_Files from outlier.outlier_commons import Outlier_Commons # INITIALIZATION # Debug.DEBUG = 1 hmp = HMP_Model() outlier = Outlier_Commons() # PROCESSING # processing = Processing_DB_Files() hmp.load_training_data_by_window_by_people('f1', 50) training, training_labels, test, test_labels = processing.calculating_features( hmp) training_outlier, training_labels_outlier, test_outlier, test_labels_outlier, \ outlier, outlier_labels = outlier.generate_outliers(training, training_labels, test, test_labels, "drink_glass")