secml.ml.features

CPreProcess

class secml.ml.features.c_preprocess.CPreProcess(preprocess=None)[source]

Bases: secml.ml.c_module.CModule

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.

n_jobs
preprocess

Inner preprocessor (if any).

verbose

Verbosity level of logger output.

Methods

backward(self[, w])

Returns the preprocessor gradient wrt data.

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 the preprocessor.

fit_forward(self, x[, y, caching])

Fit estimator using data and then execute forward on the data.

fit_transform(self, x[, y])

Fit preprocessor using data and then transform data.

forward(self, x[, caching])

Forward pass on input x.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

gradient(self, x[, w])

Compute gradient at x by doing a backward pass.

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 object from file.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

transform(self, x)

Apply the transformation algorithm on data.

fit(self, x, y=None)[source]

Fit the preprocessor.

Parameters
xCArray

Array to be used as training set. 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
CPreProcess

Instance of the trained normalizer.

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.

See also

fit

fit the preprocessor.

transform

transform input data.

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.

transform(self, x)[source]

Apply the transformation algorithm on data.

Parameters
xCArray

Array to be transformed. Shape of input array depends on the algorithm itself.

Returns
CArray

Transformed input data.