sparselm.tools#

A variety of tools for fitting linear regression models to polish CE.

sparselm.tools.constrain_coefficients(indices, high=None, low=None)[source]#

Constrain a fit method to keep coefficients within a specified range.

Use this as a standard decorator with parameters: - At runtime:

coefs = constrain_coefficients(indices, high, low)(fit_method)(X, y)

  • In fit_method definitions:

    @constrain_coefficients(indices, high, low) def your_fit_method(X, y):

Parameters:
  • indices (array or list) – indices of coefficients to constrain

  • high (float or array) – upper bound for indices,

  • low (float or array) – lower bounds for indices

sparselm.tools.r2_score_to_cv_error(score, y, y_pred, weights=None)[source]#

Convert r2 score to cross-validation error.

Parameters:
  • score (float) – An r2 score obtained from cross validation.

  • y (ArrayLike) – 1D The target vector.

  • y_pred (ArrayLike) – 1D The fitted vector.

  • weights (ArrayLike) – 1D The weights of each sample. Default to 1.

Returns:

The CV error

Return type:

float