2 ROS Anomaly Detector Framework 13 - This interface is built to help the user. 14 - This is meant to automate things. Since training files have 15 already been passed, the data can be made ready for the user 19 from pprint
import pprint
21 from sklearn
import svm
23 from data_process
import DataProcess
24 from anomaly_detector
import AnomalyDetector
25 from data_persist
import DataPersist
31 print '\n\n', os.getcwd()
34 with open(input_file,
'r') as fil: 35 local = yaml.load(fil) 41 self.
__processor = DataProcess(local[
"Operations"][
"reduction"])
52 NOTE: Specifically for fitting models 56 - BUG: Should this data be saved for future? 58 NOTE: Functions below are specifically calling fit. 61 split_x, split_y = self.__processor.split(self.
__fit_file[
"name"], \
65 scaled_x = self.__processor.scaler_fit(split_x)
66 reduced_x = self.__processor.reduction_fit(scaled_x)
67 self.__data_persist.dump_data(self.
__fit_file[
"name"], \
73 Private function, user does not need to know this. 74 Use this function to get training data ready. 75 Checks to make sure a training file has been passed. 76 If filename is Null/None, it is skipped. 89 NOTE: Can only be called if __ready_processor has been called. 90 It should be, when the instance is created. 93 split_x, split_y = self.__processor.split(item[
"name"], \
96 scaled_x = self.__processor.scaler_transform(split_x)
97 reduced_x = self.__processor.reduction_transform(scaled_x)
98 self.__data_persist.dump_data(item[
"name"], reduced_x, split_y)
103 The input 'item' refers to an item in the list of testing datasets. 105 The inputs and outputs from the datasets are first gathered. 106 Based on the training files passed in for those models, predictions 110 unsuper_preds, super_preds = [], []
112 x, y = self.__data_persist.retrieve_dumped_data(item[
"name"])
115 unsuper_preds = self.__anomaly_classifier.classify_unsupervised(
119 super_preds = self.__anomaly_classifier.classify_supervised(
124 return unsuper_preds, super_preds
129 This was written primarily as a sanity check. 130 Prints out datasets names for fitting, and training models. 143 Creates an instance of anomaly classifier. 144 Training data files already exist, so all models can and are 146 Models are ready for predictions after this stage. 148 NOTE: Training predictions are grabbed and outputs are trying 150 Once the process is set, the predictions can be ridden. 159 print '=====Unsupervised=====' 161 unsup_x, unsup_y = self.__data_persist.retrieve_dumped_data(
163 self.__anomaly_classifier.fit_unsupervised_models(unsup_x)
173 print '=====Supervised=====' 175 sup_x, sup_y = self.__data_persist.retrieve_dumped_data(
177 self.__anomaly_classifier.fit_supervised_models(sup_x, sup_y)
187 Get predictions for testing files that was passed in 197 u_preds.append(usup_preds)
198 s_preds.append(sup_preds)
200 return u_preds, s_preds
204 return self.__data_persist.retrieve_dumped_data(loc)
def get_testing_predictions(self)
def __preprocess_data_training(self)
def __init__(self, input_file)
def __preprocess_data_helper(self, item)
__unsupervised_train_file
def genmodel_train(self, unsup_models, sup_models)
def __testing_predictions_helper(self, item)
def __ready_preprocessor(self)
def retrieve_data(self, loc)