art.estimators.classification.scikitlearn

This module implements the classifiers for scikit-learn models.

Base Class Scikit-learn

class art.estimators.classification.scikitlearn.ScikitlearnClassifier(model: sklearn.base.BaseEstimator, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn classifier models.

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

Scikit-learn DecisionTreeClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnDecisionTreeClassifier(model: Optional[sklearn.tree.DecisionTreeClassifier], clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Decision Tree Classifier models.

__init__(model: Optional[sklearn.tree.DecisionTreeClassifier], clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Decision Tree Classifier model.

Parameters
  • model – scikit-learn Decision Tree Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_classes_at_node(node_id: int) → numpy.ndarray

Returns the classification for a given node.

Returns

Major class in node.

get_decision_path(x: numpy.ndarray) → numpy.ndarray

Returns the path through nodes in the tree when classifying x. Last one is leaf, first one root node.

Returns

The indices of the nodes in the array structure of the tree.

get_feature_at_node(node_id: int) → int

Returns the feature of given id for a node.

Returns

Feature index of feature split in this node.

get_left_child(node_id: int) → int

Returns the id of the left child node of node_id.

Returns

The indices of the left child in the tree.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

get_right_child(node_id: int) → int

Returns the id of the right child node of node_id.

Returns

The indices of the right child in the tree.

get_samples_at_node(node_id: int) → int

Returns the number of training samples mapped to a node.

Returns

Number of samples mapped this node.

get_threshold_at_node(node_id: int) → float

Returns the threshold of given id for a node.

Returns

Threshold value of feature split in this node.

get_values_at_node(node_id: int) → numpy.ndarray

Returns the feature of given id for a node.

Returns

Normalized values at node node_id.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn ExtraTreeClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnExtraTreeClassifier(model: sklearn.tree.ExtraTreeClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Extra TreeClassifier Classifier models.

__init__(model: sklearn.tree.ExtraTreeClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Extra TreeClassifier Classifier model.

Parameters
  • model – scikit-learn Extra TreeClassifier Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_classes_at_node(node_id: int) → numpy.ndarray

Returns the classification for a given node.

Returns

Major class in node.

get_decision_path(x: numpy.ndarray) → numpy.ndarray

Returns the path through nodes in the tree when classifying x. Last one is leaf, first one root node.

Returns

The indices of the nodes in the array structure of the tree.

get_feature_at_node(node_id: int) → int

Returns the feature of given id for a node.

Returns

Feature index of feature split in this node.

get_left_child(node_id: int) → int

Returns the id of the left child node of node_id.

Returns

The indices of the left child in the tree.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

get_right_child(node_id: int) → int

Returns the id of the right child node of node_id.

Returns

The indices of the right child in the tree.

get_samples_at_node(node_id: int) → int

Returns the number of training samples mapped to a node.

Returns

Number of samples mapped this node.

get_threshold_at_node(node_id: int) → float

Returns the threshold of given id for a node.

Returns

Threshold value of feature split in this node.

get_values_at_node(node_id: int) → numpy.ndarray

Returns the feature of given id for a node.

Returns

Normalized values at node node_id.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn AdaBoostClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnAdaBoostClassifier(model: sklearn.ensemble.AdaBoostClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn AdaBoost Classifier models.

__init__(model: sklearn.ensemble.AdaBoostClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn AdaBoost Classifier model.

Parameters
  • model – scikit-learn AdaBoost Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn BaggingClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnBaggingClassifier(model: sklearn.ensemble.BaggingClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Bagging Classifier models.

__init__(model: sklearn.ensemble.BaggingClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Bagging Classifier model.

Parameters
  • model – scikit-learn Bagging Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn ExtraTreesClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnExtraTreesClassifier(model: sklearn.ensemble.ExtraTreesClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Extra Trees Classifier models.

__init__(model: sklearn.ensemble.ExtraTreesClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Create a Classifier instance from a scikit-learn Extra Trees Classifier model.

Parameters
  • model – scikit-learn Extra Trees Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

get_trees() → List[Tree]

Get the decision trees.

Returns

A list of decision trees.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn GradientBoostingClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnGradientBoostingClassifier(model: sklearn.ensemble.GradientBoostingClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Gradient Boosting Classifier models.

__init__(model: sklearn.ensemble.GradientBoostingClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Gradient Boosting Classifier model.

Parameters
  • model – scikit-learn Gradient Boosting Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

get_trees() → List[Tree]

Get the decision trees.

Returns

A list of decision trees.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn RandomForestClassifier Classifier

class art.estimators.classification.scikitlearn.ScikitlearnRandomForestClassifier(model: sklearn.ensemble.RandomForestClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Random Forest Classifier models.

__init__(model: sklearn.ensemble.RandomForestClassifier, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Random Forest Classifier model.

Parameters
  • model – scikit-learn Random Forest Classifier model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

get_trees() → List[Tree]

Get the decision trees.

Returns

A list of decision trees.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn LogisticRegression Classifier

class art.estimators.classification.scikitlearn.ScikitlearnLogisticRegression(model: sklearn.linear_model.LogisticRegression, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn Logistic Regression models.

__init__(model: sklearn.linear_model.LogisticRegression, clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn Logistic Regression model.

Parameters
  • model – scikit-learn LogisticRegression model

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

class_gradient(*args, **kwargs)

Compute per-class derivatives w.r.t. x.

Parameters
  • x – Sample input with shape as expected by the model.

  • label – Index of a specific per-class derivative. If an integer is provided, the gradient of that class output is computed for all samples. If multiple values as provided, the first dimension should match the batch size of x, and each value will be used as target for its corresponding sample in x. If None, then gradients for all classes will be computed for each sample.

Returns

Array of gradients of input features w.r.t. each class in the form (batch_size, nb_classes, input_shape) when computing for all classes, otherwise shape becomes (batch_size, 1, input_shape) when label parameter is specified.

Raises
  • ValueError – If the model has not been fitted prior to calling this method or if the number of classes in the classifier is not known.

  • TypeError – If the requested label cannot be processed.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

loss_gradient(*args, **kwargs)

Compute the gradient of the loss function w.r.t. x.

Parameters
  • x – Sample input with shape as expected by the model.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape (nb_samples,).

Returns

Array of gradients of the same shape as x.

Raises

ValueError – If the model has not been fitted prior to calling this method.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

Raises

ValueError – If the classifier does not have methods predict or predict_proba.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.

Scikit-learn SVC Classifier

class art.estimators.classification.scikitlearn.ScikitlearnSVC(model: Union[sklearn.svm.SVC, sklearn.svm.LinearSVC], clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1)

Wrapper class for scikit-learn C-Support Vector Classification models.

__init__(model: Union[sklearn.svm.SVC, sklearn.svm.LinearSVC], clip_values: Optional[CLIP_VALUES_TYPE] = None, preprocessing_defences: Optional[Union[Preprocessor, List[Preprocessor]]] = None, postprocessing_defences: Optional[Union[Postprocessor, List[Postprocessor]]] = None, preprocessing: PREPROCESSING_TYPE = 0, 1) → None

Create a Classifier instance from a scikit-learn C-Support Vector Classification model.

Parameters
  • model – scikit-learn C-Support Vector Classification model.

  • clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.

  • preprocessing_defences – Preprocessing defence(s) to be applied by the classifier.

  • postprocessing_defences – Postprocessing defence(s) to be applied by the classifier.

  • preprocessing – Tuple of the form (subtractor, divider) of floats or np.ndarray of values to be used for data preprocessing. The first value will be subtracted from the input. The input will then be divided by the second one.

class_gradient(*args, **kwargs)

Compute per-class derivatives w.r.t. x.

Parameters
  • x – Sample input with shape as expected by the model.

  • label – Index of a specific per-class derivative. If an integer is provided, the gradient of that class output is computed for all samples. If multiple values as provided, the first dimension should match the batch size of x, and each value will be used as target for its corresponding sample in x. If None, then gradients for all classes will be computed for each sample.

Returns

Array of gradients of input features w.r.t. each class in the form (batch_size, nb_classes, input_shape) when computing for all classes, otherwise shape becomes (batch_size, 1, input_shape) when label parameter is specified.

property clip_values

Return the clip values of the input samples.

Returns

Clip values (min, max).

fit(*args, **kwargs)

Fit the classifier on the training set (x, y).

Parameters
  • x – Training data.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes).

  • kwargs – Dictionary of framework-specific arguments. These should be parameters supported by the fit function in sklearn classifier and will be passed to this function as such.

get_params() → Dict[str, Any]

Get all parameters and their values of this estimator.

Returns

A dictionary of string parameter names to their value.

property input_shape

Return the shape of one input sample.

Returns

Shape of one input sample.

loss_gradient(*args, **kwargs)

Compute the gradient of the loss function w.r.t. x. Following equation (1) with lambda=0.

Parameters
  • x – Sample input with shape as expected by the model.

  • y – Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape (nb_samples,).

Returns

Array of gradients of the same shape as x.

property model

Return the model.

Returns

The model.

property nb_classes

Return the number of output classes.

Returns

Number of classes in the data.

predict(*args, **kwargs)

Perform prediction for a batch of inputs.

Parameters

x – Test set.

Returns

Array of predictions of shape (nb_inputs, nb_classes).

q_submatrix(rows: numpy.ndarray, cols: numpy.ndarray) → numpy.ndarray

Returns the q submatrix of this SVM indexed by the arrays at rows and columns.

Return type

ndarray

Parameters
  • rows (ndarray) – The row vectors.

  • cols (ndarray) – The column vectors.

Returns

A submatrix of Q.

set_params(**kwargs) → None

Take a dictionary of parameters and apply checks before setting them as attributes.

Parameters

kwargs – A dictionary of attributes.