alibi.confidence.model_linearity module

class alibi.confidence.model_linearity.LinearityMeasure(method='grid', epsilon=0.04, nb_samples=10, res=100, alphas=None, model_type='classifier', agg='pairwise', verbose=False)[source]

Bases: object

__init__(method='grid', epsilon=0.04, nb_samples=10, res=100, alphas=None, model_type='classifier', agg='pairwise', verbose=False)[source]
Parameters
  • method (str) – Method for sampling. Supported methods are ‘knn’ or ‘grid’.

  • epsilon (float) – Size of the sampling region around the central instance as a percentage of the features range.

  • nb_samples (int) – Number of samples to generate.

  • res (int) – Resolution of the grid. Number of intervals in which the feature range is discretized.

  • alphas (Optional[ndarray]) – Coefficients in the superposition.

  • agg (str) – Aggregation method. Supported values are ‘global’ or ‘pairwise’.

  • model_type (str) – Type of task. Supported values are ‘regressor’ or ‘classifier’.

Return type

None

fit(X_train)[source]
Parameters

X_train (ndarray) – Training set

Return type

None

Returns

None

score(predict_fn, x)[source]
Parameters
  • predict_fn (Callable) – Prediction function

  • x (ndarray) – Instance of interest

Return type

ndarray

Returns

Linearity measure

alibi.confidence.model_linearity.linearity_measure(predict_fn, x, feature_range=None, method='grid', X_train=None, epsilon=0.04, nb_samples=10, res=100, alphas=None, agg='global', model_type='classifier')[source]

Calculate the linearity measure of the model around an instance of interest x.

Parameters
  • predict_fn (Callable) – Predict function.

  • x (ndarray) – Instance of interest.

  • feature_range (Union[List, ndarray, None]) – Array with min and max values for each feature.

  • method (str) – Method for sampling. Supported values ‘knn’ or ‘grid’.

  • X_train (Optional[ndarray]) – Training set.

  • epsilon (float) – Size of the sampling region as a percentage of the feature range.

  • nb_samples (int) – Number of samples to generate.

  • res (int) – Resolution of the grid. Number of intervals in which the features range is discretized.

  • alphas (Optional[ndarray]) – Coefficients in the superposition.

  • agg (str) – Aggregation method. Supported values ‘global’ or ‘pairwise’.

  • model_type (str) – Type of task. Supported values ‘regressor’ or ‘classifier’.

Return type

ndarray

Returns

Linearity measure