models.sklearn_wrap#

Module: models.sklearn_wrap#

Inheritance diagram for ISLP.models.sklearn_wrap:

digraph inheritance86e7436895 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "models.sklearn_wrap.sklearn_selected" [URL="#ISLP.models.sklearn_wrap.sklearn_selected",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Parameters"]; "models.sklearn_wrap.sklearn_sm" -> "models.sklearn_wrap.sklearn_selected" [arrowsize=0.5,style="setlinewidth(0.5)"]; "models.sklearn_wrap.sklearn_selection_path" [URL="#ISLP.models.sklearn_wrap.sklearn_selection_path",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Parameters"]; "models.sklearn_wrap.sklearn_sm" -> "models.sklearn_wrap.sklearn_selection_path" [arrowsize=0.5,style="setlinewidth(0.5)"]; "models.sklearn_wrap.sklearn_sm" [URL="#ISLP.models.sklearn_wrap.sklearn_sm",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Parameters"]; "sklearn.base.BaseEstimator" -> "models.sklearn_wrap.sklearn_sm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "sklearn.base.RegressorMixin" -> "models.sklearn_wrap.sklearn_sm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "sklearn.base.BaseEstimator" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for all estimators in scikit-learn."]; "sklearn.base.RegressorMixin" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Mixin class for all regression estimators in scikit-learn."]; }

Wrappers for statsmodels#

Classes#

sklearn_selected#

class ISLP.models.sklearn_wrap.sklearn_selected(model_type, strategy, model_args={}, scoring=None, cv=None)#

Bases: sklearn_sm

Parameters:
model_typeclass

A model type from statsmodels, e.g. sm.OLS or sm.GLM

strategyStrategy

A search strategy

model_argsdict (optional)

Arguments passed to the statsmodels model.

scoringstr or callable, default=None

A str (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y) which should return only a single value.

cv: int, cross-validation generator or an iterable, default=None

Determines the cross-validation splitting strategy.

Methods

fit(X, y)

First, select a model with design matrix determined from X and response y.

get_params([deep])

Get parameters for this estimator.

predict(X)

Compute predictions for design matrix X in selected model.

score(X, y[, sample_weight])

Score a statsmodel model with test design matrix X and test response y.

set_params(**params)

Set the parameters of this estimator.

__init__(model_type, strategy, model_args={}, scoring=None, cv=None)#
fit(X, y)#

First, select a model with design matrix determined from X and response y. Then, fit selected model.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

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.

predict(X)#

Compute predictions for design matrix X in selected model.

Parameters:
Xarray-like

Design matrix.

score(X, y, sample_weight=None)#

Score a statsmodel model with test design matrix X and test response y.

If model_type is OLS, use MSE. For a GLM this computes (average) deviance.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

sample_weightNone

Optional sample weights.

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.

sklearn_selection_path#

class ISLP.models.sklearn_wrap.sklearn_selection_path(model_type, strategy, model_args={}, scoring=None, cv=None)#

Bases: sklearn_sm

Parameters:
model_typeclass

A model type from statsmodels, e.g. sm.OLS or sm.GLM

strategyStrategy

A search strategy

model_argsdict (optional)

Arguments passed to the statsmodels model.

scoringstr or callable, default=None

A str (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y) which should return only a single value.

cv: int, cross-validation generator or an iterable, default=None

Determines the cross-validation splitting strategy.

Methods

fit(X, y)

First, select a model with design matrix determined from X and response y.

get_params([deep])

Get parameters for this estimator.

predict(X)

Compute predictions along selection path for design matrix X.

score(X, y[, sample_weight])

Score a statsmodel model with test design matrix X and test response y.

set_params(**params)

Set the parameters of this estimator.

__init__(model_type, strategy, model_args={}, scoring=None, cv=None)#
fit(X, y)#

First, select a model with design matrix determined from X and response y. Then, fit selected model.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

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.

predict(X)#

Compute predictions along selection path for design matrix X.

Parameters:
Xarray-like

Design matrix.

score(X, y, sample_weight=None)#

Score a statsmodel model with test design matrix X and test response y.

If model_type is OLS, use MSE. For a GLM this computes (average) deviance.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

sample_weightNone

Optional sample weights.

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.

sklearn_sm#

class ISLP.models.sklearn_wrap.sklearn_sm(model_type, model_spec=None, model_args={})#

Bases: BaseEstimator, RegressorMixin

Parameters:
model_type: class

A model type from statsmodels, e.g. sm.OLS or sm.GLM

model_spec: ModelSpec

Specify the design matrix.

model_args: dict (optional)

Arguments passed to the statsmodels model.

Notes

If model_str is present, then X and Y are presumed to be pandas objects that are placed into a dataframe before formula is evaluated. This affects fit and predict methods.

Methods

fit(X, y)

Fit a statsmodel model with design matrix determined from X and response y.

get_params([deep])

Get parameters for this estimator.

predict(X)

Compute predictions for design matrix X.

score(X, y[, sample_weight])

Score a statsmodel model with test design matrix X and test response y.

set_params(**params)

Set the parameters of this estimator.

__init__(model_type, model_spec=None, model_args={})#
fit(X, y)#

Fit a statsmodel model with design matrix determined from X and response y.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

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.

predict(X)#

Compute predictions for design matrix X.

Parameters:
Xarray-like

Design matrix.

score(X, y, sample_weight=None)#

Score a statsmodel model with test design matrix X and test response y.

If model_type is OLS, use MSE. For a GLM this computes (average) deviance.

Parameters:
Xarray-like

Design matrix.

yarray-like

Response vector.

sample_weightNone

Optional sample weights.

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.