fatf.transparency.sklearn.linear_model.SKLearnLinearModelExplainer

class fatf.transparency.sklearn.linear_model.SKLearnLinearModelExplainer(clf: sklearn.base.BaseEstimator, feature_names: Optional[List[str]] = None, class_names: Optional[List[str]] = None)[source]

A scikit-learn linear model explainer class.

New in version 0.0.2.

This class implements a feature_importance method that returns coefficients of the linear clf model. This coefficients can be interpreted as features (positive or negative) importance.

Note

Please note that for the coefficients (feature importances) to be comparable the values of all features had to be normalised to the same range before training the model.

For other functionality, parameters, attributes, logs, warnings and errors implemented by this class please see its parent class: fatf.transparency.sklearn.tools.SKLearnExplainer.

Methods

explain_instance()

Generates an explanation of a single data point (instance).

explain_model()

Generates a model explanation.

feature_importance()

Extracts features importance from the clf predictor.

map_class(clf_class, str])

Maps a class id outputted by the classifier to a class name.

explain_instance() → numpy.ndarray[source]

Generates an explanation of a single data point (instance).

This can be an explanation of a data point from a data set or of a prediction provided by a predictive model.

explain_model() → numpy.ndarray[source]

Generates a model explanation.

feature_importance() → numpy.ndarray[source]

Extracts features importance from the clf predictor.

Returns
feature_importance_arraynumpy.ndarray

A numpy array with coefficients of the clf linear model. (The order of the coefficients corresponds to the order of the features in the training data array.)

map_class(clf_class: Union[int, str]) → str[source]

Maps a class id outputted by the classifier to a class name.

A mapping will only be provided if the class was initialised with class names or an array of possible predictions was extracted form the classifier.

Parameters
clf_classUnion[integer, string]

A class id outputted by the classifier.

Returns
mapped_classstring

A class name corresponding to the class id.

Raises
RuntimeError

The error is raised when trying to map a class for a regressor. It is also raised if the class was not sufficiently initialised, i.e., either classes_array or class_names attributes are missing.

TypeError

The clf_class parameter is neither integer nor string.

ValueError

Given clf_class is not one of the values that the classifier can output.