fracridge.FracRidgeRegressor

class FracRidgeRegressor(fracs=None, fit_intercept=False, copy_X=True, tol=1e-10, jit=True)[source]
Parameters:
fracsfloat or sequence

The desired fractions of the parameter vector length, relative to OLS solution. Default: np.arange(.1, 1.1, .1)

fit_interceptbool, optional

Whether to fit an intercept term. Default: False.

copy_Xbool, optional

Whether to make a copy of the X matrix before fitting. Default: True.

tolfloat, optional.

Tolerance under which singular values of the X matrix are considered to be zero. Default: 1e-10.

jitbool, optional.

Whether to use jit-accelerated implementation. Default: True.

Attributes:
coef_ndarray, shape (p, f, b)

The full estimated parameters across units of measurement for every desired fraction. Where p number of model parameters, f number of fractions and b number of targets.

alpha_ndarray, shape (f, b)

The alpha coefficients associated with each solution. Where f number of fractions and b number of targets.

Examples

Generate random data:

>>> np.random.seed(1)
>>> y = np.random.randn(100)
>>> X = np.random.randn(100, 10)

Calculate coefficients with naive OLS:

>>> coef = np.linalg.inv(X.T @ X) @ X.T @ y

Initialize the estimator with a single fraction:

>>> fr = FracRidgeRegressor(fracs=0.3)

Fit estimator:

>>> fr.fit(X, y)
FracRidgeRegressor(fracs=0.3)

Check results:

>>> coef_ = fr.coef_
>>> alpha_ = fr.alpha_
>>> print(np.linalg.norm(coef_) / np.linalg.norm(coef))
0.29
__init__(fracs=None, fit_intercept=False, copy_X=True, tol=1e-10, jit=True)[source]
get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

score(X, y)[source]

Score the fracridge fit

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

Examples using fracridge.FracRidgeRegressor

Integrating FracRidge objects into sklearn pipelines

Integrating FracRidge objects into sklearn pipelines

Comparing alpha and fracs

Comparing alpha and fracs

Coefficient paths and cross-validation curves

Coefficient paths and cross-validation curves