4 Ensemble Anomaly Detector Framework 9 Example of training script for ROS module 20 import matplotlib.pyplot
as plt
21 from mpl_toolkits.mplot3d
import Axes3D
22 from mpl_toolkits.mplot3d.art3d
import Poly3DCollection
23 from sklearn
import svm
26 from sklearn.decomposition
import PCA
32 print y_pred_test.shape
34 te0, te1, te2 = test[:, 0], test[:, 1], test[:, 2]
35 y_pred_test = y_pred_test[0]
38 ax = fig.gca(projection=
'3d')
40 ax.scatter(te0, te1, te2, c=y_pred_test, \
49 pca = PCA(n_components=3)
52 data = pca.transform(data)
58 if __name__ ==
"__main__":
60 unsupervised_models = []
61 supervised_models = []
67 input_file = sys.argv[1]
72 with open(input_file,
'r') as fil: 73 local = yaml.load(fil) 75 fit_file = local["Files"][
"fit_file"]
76 unsupervised_train_file = local[
"Files"][
"unsupervised_train"]
77 supervised_train_file = local[
"Files"][
"supervised_train"]
78 testing_file = local[
"Files"][
"testing"]
80 clf_ocsvm17 = svm.OneClassSVM(nu=0.05, kernel=
"rbf", gamma=1000)
81 unsupervised_models.append((
'ocsvm17', clf_ocsvm17))
82 clf_ocsvm18 = svm.OneClassSVM(nu=0.06, kernel=
"rbf", gamma=1100)
83 unsupervised_models.append((
'ocsvm18', clf_ocsvm18))
86 clf_rbfsvm1 = svm.SVC(kernel=
'rbf', gamma=150, C=100000)
87 supervised_models.append((
'clf_rbfsvm1', clf_rbfsvm1))
91 interface.genmodel_train(unsupervised_models, supervised_models)
97 u_preds, s_preds = interface.get_testing_predictions()
101 x, y = interface.retrieve_data(testing_file[0][
"name"])
103 print 'x shape: ', x.shape
104 print 'y shape: ', np.array(y).shape
def reduce_graph_3d(data, preds)
def graph_3d(test, y_pred_test)