models.sklearn_wrap#
Module: models.sklearn_wrap#
Inheritance diagram for ISLP.models.sklearn_wrap:
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.