2 ROS Anomaly Detector Framework 14 from sklearn
import svm
16 from output_matrix
import OutputMatrix
17 from sklearn.externals
import joblib
19 from pprint
import pprint
27 self.__unsup_clfs = unsup_models
36 'Private' fit unsupervised models method 37 Iterate through all models 44 saveloc =
'../data/'+current_model[0]+
'.pkl' 45 if os.path.exists(saveloc):
46 current_model = (current_model[0], joblib.load(saveloc))
48 current_model[1].fit(data)
49 joblib.dump(current_model[1], saveloc)
53 unsuper_clfs.append(saveloc)
59 'Private' fit supervised models method 60 Iterate through all models 67 saveloc =
'../data/'+current_model[0]+
'.pkl' 68 if os.path.exists(saveloc):
69 current_model = (current_model[0], joblib.load(saveloc))
71 current_model[1].fit(data_x, data_y.ravel())
72 joblib.dump(current_model[1], saveloc)
76 super_clfs.append(saveloc)
82 Given a model, prediction is made. 84 BUG: Assuming model is used as a binary classifier, 85 predictions are turned to 0/1 vs 1/-1 87 predictions = model[1].predict(data)
96 Unsupervised data is mixed. Labels (y) are passed in. 103 Supervised data is meant to all be safe. No labels. 110 Get predictions for unsupervised models. 111 Calls 'private' method with model for predictions. 112 For the dataset that is passed in, all supervised model 113 results are compiled. 114 With the output labels, the output matrix is called. 121 all_preds.append(preds)
123 all_preds = np.array(all_preds)
125 print 'Supervised results for', dataset_name
126 print 'Order of results: ', [item[0]
for item
in self.
__sup_clfs]
133 Get predictions for unsupervised models. 134 Calls 'private' method with model for predictions. 135 For the dataset that is passed in, all unsupervised model 136 results are compiled. 137 With the output labels, the output matrix is called. 144 all_preds.append(preds)
146 all_preds = np.array(all_preds)
148 print 'Unsupervised results for', dataset_name
149 print 'Order of results: ', [item[0]
for item
in self.
__unsup_clfs]
156 Predictions for multiple classifiers are being 157 passed, so need to iterate through them. 160 self.__outputMat.output_matrix(true_y, item)
def classify_unsupervised(self, dataset_name, in_data, out_label)
def call_output(self, true_y, pred_y)
def __classify(self, model, data)
def __init__(self, unsup_models, sup_models)
def fit_supervised_models(self, sup_train_x, sup_train_y)
def fit_unsupervised_models(self, data_x)
def __fit_unsupervised(self, data)
def __fit_supervised(self, data_x, data_y)
def classify_supervised(self, dataset_name, in_data, out_label)