secml.ml.features¶
CPreProcess¶
-
class
secml.ml.features.c_preprocess.
CPreProcess
(preprocess=None)[source]¶ Bases:
secml.core.c_creator.CCreator
Common interface for feature preprocessing algorithms.
- Parameters
- preprocessCPreProcess or str or None, optional
Features preprocess to be applied to input data. Can be a CPreProcess subclass or a string with the type of the desired preprocessor. If None, input data is used as is.
- Attributes
class_type
Defines class type.
logger
Logger for current object.
preprocess
Inner preprocessor (if any).
verbose
Verbosity level of logger output.
Methods
copy
(self)Returns a shallow copy of current class.
create
([class_item])This method creates an instance of a class with given type.
create_chain
(class_items, kwargs_list)Creates a chain of preprocessors.
deepcopy
(self)Returns a deep copy of current class.
fit
(self, x[, y])Fit transformation algorithm.
fit_transform
(self, x[, y])Fit preprocessor using data and then transform data.
get_class_from_type
(class_type)Return the class associated with input type.
get_params
(self)Returns the dictionary of class parameters.
get_subclasses
()Get all the subclasses of the calling class.
gradient
(self, x[, w])Returns the preprocessor gradient wrt data.
inverse_transform
(self, x)Revert data to original form.
list_class_types
()This method lists all types of available subclasses of calling one.
load
(path)Loads class from pickle object.
revert
(self, x)Deprecated since version 0.9.
save
(self, path)Save class object using pickle.
set
(self, param_name, param_value[, copy])Set a parameter that has a specific name to a specific value.
set_params
(self, params_dict[, copy])Set all parameters passed as a dictionary {key: value}.
timed
([msg])Timer decorator.
transform
(self, x)Apply the transformation algorithm on data.
-
static
create_chain
(class_items, kwargs_list)[source]¶ Creates a chain of preprocessors.
- Parameters
- class_itemslist of str or class instances
A list of mixed class types or CPreProcess instances. The object created with the first type/instance of the list will be the preprocess of the object created using the second type/instance in the list and so on until the end of the list.
- kwargs_listlist of dict
A list of dictionaries, one for each item in class_items, to specify any additional argument for each specific preprocessor.
- Returns
- CPreProcess
The chain of preprocessors.
-
fit
(self, x, y=None)[source]¶ Fit transformation algorithm.
- Parameters
- xCArray
Array to be used for training. Shape of input array depends on the algorithm itself.
- yCArray or None, optional
Flat array with the label of each pattern. Can be None if not required by the preprocessing algorithm.
- Returns
- CPreProcess
Instance of the trained preprocessor.
-
fit_transform
(self, x, y=None)[source]¶ Fit preprocessor using data and then transform data.
This method is equivalent to call fit(data) and transform(data) in sequence, but it’s useful when data is both the training array and the array to be transformed.
- Parameters
- xCArray
Array to be transformed. Each row must correspond to one single patterns, so each column is a different feature.
- yCArray or None, optional
Flat array with the label of each pattern. Can be None if not required by the preprocessing algorithm.
- Returns
- CArray
Transformed input data.
-
gradient
(self, x, w=None)[source]¶ Returns the preprocessor gradient wrt data.
- Parameters
- xCArray
Data array, 2-Dimensional or ravel.
- wCArray or None, optional
If CArray, will be left-multiplied to the gradient of the preprocessor.
- Returns
- gradientCArray
Gradient of the preprocessor wrt input data. Array of shape (x.shape[1], x.shape[1]) if w is None, otherwise an array of shape (w.shape[0], x.shape[1]). If w.shape[0] is 1, result will be raveled.
-
inverse_transform
(self, x)[source]¶ Revert data to original form.
- Parameters
- xCArray
Transformed array to be reverted to original form. Shape of input array depends on the algorithm itself.
- Returns
- CArray
Original input data.
Warning
Reverting a transformed array is not always possible. See description of each preprocessor for details.
-
property
preprocess
¶ Inner preprocessor (if any).