The xrf package#

class xrf.XRandomForestClassifier(**kwargs)[source]#

Explainable Random Forest Classifier.

An explainable random forest classifier is generated in the same way as a standard random forest classifier, but provides example attributions, i.e., each prediction is associated with a weight distribution over the training examples, and allows for selecting a subset of the examples with the highest weight when forming predictions.

The same set of parameters are available as for sklearn.ensemble.RandomForestClassifier

Methods

fit(X, y)

Fit explainable random forest classifier.

predict(X[, k, c, return_examples, ...])

Predict class for X.

predict_proba(X[, k, c, return_examples, ...])

Predict class probabilities for X.

fit(X, y)[source]#

Fit explainable random forest classifier.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – training objects

  • y (array-like of shape (n_values,)) – training labels (numerical values)

Returns:

self – Fitted XRandomForestClassifier.

Return type:

object

predict_proba(X, k=None, c=None, return_examples=False, return_weights=False, normalize_weights=True)[source]#

Predict class probabilities for X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – test objects

  • k (no. of top-weighted training examples to use when forming) – predictions, default=None

  • c (cumulative weight of top-weighted training examples to use when) – forming predictions, default=None

  • return_examples (Boolean, default=False) – whether or not to output the indexes of training examples that are used when forming predictions

  • return_weights (Boolean, default=False) – whether or not to output the weights of the training examples that are used when forming predictions (in decreasing order)

  • normalize_weights (Boolean, default=True) – whether returned weights should be normalized or not

Returns:

  • probabilities (ndarray of (n_samples,n_classes) with real values) – class probability distributions

  • examples (ndarray of (n_samples, k) or (n_samples, ) of lists) – indexes of training examples used when forming predictions Only returned if return_examples == True.

  • weights (ndarray of (n_samples, k) or (n_samples, ) of lists) – example weights used when forming predictions Only returned if return_weights == True.

predict(X, k=None, c=None, return_examples=False, return_weights=False, normalize_weights=True)[source]#

Predict class for X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – test objects

  • k (no. of top-weighted training examples to use when forming) – predictions, default=None

  • c (cumulative weight of top-weighted training examples to use when) – forming predictions, default=None

  • return_examples (Boolean, default=False) – whether or not to output the indexes of training examples that are used when forming predictions

  • return_weights (Boolean, default=False) – whether or not to output the weights of the training examples that are used when forming predictions (in decreasing order)

  • normalize_weights (Boolean, default=True) – whether returned weights should be normalized or not

Returns:

  • labels (ndarray of (n_samples,) with class labels) – predicted classes

  • examples (ndarray of (n_samples, k) or (n_samples, ) of lists) – indexes of training examples used when forming predictions Only returned if return_examples == True.

  • weights (ndarray of (n_samples, k) or (n_samples, ) of lists) – example weights used when forming predictions Only returned if return_weights == True.

class xrf.XRandomForestRegressor(**kwargs)[source]#

Explainable Random Forest Regressor.

An explainable random forest regressor is generated in the same way as a standard random forest regressor, but provides example attributions, i.e., each prediction is associated with a weight distribution over the training examples, and allows for selecting a subset of the examples with the highest weight when forming predictions.

The same set of parameters are available as for sklearn.ensemble.RandomForestRegressor

Methods

fit(X, y)

Fit explainable random forest regressor.

predict(X[, k, c, return_examples, ...])

Predict regression target for X.

fit(X, y)[source]#

Fit explainable random forest regressor.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – training objects

  • y (array-like of shape (n_values,)) – training labels (numerical values)

Returns:

self – Fitted XRandomForestRegressor.

Return type:

object

predict(X, k=None, c=None, return_examples=False, return_weights=False, normalize_weights=True)[source]#

Predict regression target for X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – test objects

  • k (no. of top-weighted training examples to use when forming) – predictions, default=None

  • c (cumulative weight of top-weighted training examples to use when) – forming predictions, default=None

  • return_examples (Boolean, default=False) – whether or not to output the indexes of training examples that are used when forming predictions

  • return_weights (Boolean, default=False) – whether or not to output the weights of the training examples that are used when forming predictions (in decreasing order)

  • normalize_weights (Boolean, default=True) – whether returned weights should be normalized or not

Returns:

  • predictions (ndarray of (n_samples,) with real values) – point predictions

  • examples (ndarray of (n_samples, k) or (n_samples, ) of lists) – indexes of training examples used when forming predictions Only returned if return_examples == True.

  • weights (ndarray of (n_samples, k) or (n_samples, ) of lists) – example weights used when forming predictions Only returned if return_weights == True.