2 ROS Anomaly Detector Framework 13 from sklearn.preprocessing
import MinMaxScaler
14 from sklearn.decomposition
import PCA
15 from sklearn.utils
import shuffle
17 from sklearn.externals
import joblib
23 Specifically for processing data and getting it ready 24 for anomaly detection. 28 self.
__scale = MinMaxScaler(feature_range=(0, 1))
37 def split(self, in_file, x_cols, y_cols):
38 ''' Read csv, to dataframe, split to x and y. ''' 41 dataframe = pd.read_csv(in_file, header=
None, engine=
'python')
42 dataset = dataframe.values
43 data = shuffle(dataset)
46 data = np.unique(data, axis=0)
48 dataframe_x = data[:, x_cols]
49 dataframe_y = data[:, y_cols]
51 return dataframe_x, dataframe_y
55 ''' Fit scaling object ''' 59 saveloc =
'../data/scale.pkl' 60 if os.path.exists(saveloc):
61 self.
__scale = joblib.load(saveloc)
62 data = self.__scale.transform(data)
64 data = self.__scale.fit_transform(data)
65 joblib.dump(self.
__scale, saveloc)
71 ''' Data supplied is scaled and returned. ''' 72 transformed_data = self.__scale.transform(data)
73 return transformed_data
77 ''' Fit PCA decomposition. ''' 81 saveloc =
'../data/reduce.pkl' 82 if os.path.exists(saveloc):
84 data = self.__reduction.transform(data)
86 data = self.__reduction.fit(data)
93 ''' Reduce dimensionality of given data. ''' 96 transformed_data = self.__reduction.transform(data)
97 return transformed_data
102 ''' Return number of components passed to PCA''' def scaler_transform(self, data)
def get_reduction_size(self)
def scaler_fit(self, data)
def __init__(self, comps)
def split(self, in_file, x_cols, y_cols)
def reduction_transform(self, data)
def reduction_fit(self, data)