posthoc.Workbench

class posthoc.Workbench(model, cov=None, pattern_modifier=None, normalizer_modifier=None)

Work bench for post-hoc alteration of a linear model.

Decomposes the .coef_ of a linear model into a covariance matrix, a pattern and a normalizer. These components are then altered by user speficied functions and the linear model is re-assembled.

Parameters:
model : instance of sklearn.linear_model.LinearModel

The linear model to alter.

cov : instance of CovEstimator | function | None

The method used to estimate the covariance. Can either be one of the predefined CovEstimator objects, or a function. If a function is used, it must have the signature: def cov_modifier(cov, X, y), take the training data as input and return a matrix that will be added to the emperical covariance matrix. Defaults to None, which means the default empirical estimator of the covariance matrix is used.

pattern_modifier : function | None

Function that takes a pattern (an ndarray of shape (n_features, n_targets)) and modifies it. Must have the signature: def pattern_modifier(pattern, X, y) and return the modified pattern. Defaults to None, which means no modification of the pattern.

normalizer_modifier : function | None

Function that takes a normalizer (an ndarray of shape (n_targets, n_targets)) and modifies it. Must have the signature: def normalizer_modifier(coef, X, y, pattern, coef) and return the modified normalizer. Defaults to None, which means no modification of the normalizer.

Attributes:
coef_ : ndarray, shape (n_targets, n_features)

Matrix containing the filter weights.

intercept_ : ndarray, shape (n_targets)

The intercept of the linear model.

pattern_ : ndarray, shape (n_features, n_targets)

The altered pattern.

normalizer_ : ndarray, shape (n_targets, n_targets)

The altered normalizer.

Methods

fit(X, y) Fit the model to the data.
fit_transform(X[, y]) Fit to data, then transform it.
get_params([deep]) Get parameters for this estimator.
inverse_predict(y) Apply the inverse of the linear model to the targets.
predict(X) Predict using the linear model
score(X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.
set_params(**params) Set the parameters of this estimator.
transform(X) Apply the model to the data.
__hash__($self, /)

Return hash(self).