mcmodels.regressors.NadarayaWatsonCV

class mcmodels.regressors.NadarayaWatsonCV(param_grid, scoring=None, cv=None, store_cv_scores=False, kernel='linear', degree=3, coef0=1, gamma=None, kernel_params=None)[source]

NadarayaWatson Estimator with built in Leave-one-out cross validation.

By default, it performs Leave-one-out cross validation efficiently, but can accept cv argument to perform arbitrary cross validation splits.

Parameters:
param_grid : dict or list of dictionaries

Dictionary with parameters names (string) as keys and lists of parameter settings to try as values or a list of such dictionaries, in which case the grids spanned by each dictionary in the list are explored. This enables searching over any sequence of parameter settings.

scoring : string, callable or None, optional, default: None

A string (see sklearn.model_evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y)

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

Determines the cross-validation splitting strategy. If None, perform efficient leave-one-out cross validation, else use sklearn.model_selection.GridSearchCV.

store_cv_scores : boolean, optional, default=False

Flag indicating if the cross-validation values should be stored in cv_scores_ attribute. This flag is only compatible with cv=None.

Examples

>>> import numpy as np
>>> from mcmodels.regressors import NadarayaWatson
>>> # generate some fake data
>>> n_samples, n_features = 10, 5
>>> np.random.seed(0)
>>> y = np.random.randn(n_samples)
>>> X = np.random.randn(n_samples, n_features)
>>> # fit regressor
>>> param_grid = [dict(kernel=['linear'], degree=np.arange(1, 4)),
...               dict(kernel=['rbf'], gamma=np.logspace(-1, 1, 3))]
>>> reg = NadarayaWatsonCV(param_grid)
>>> reg.fit(X, y)
NadarayaWatsonCV(coef0=1, cv=None, degree=3, gamma=1.0, kernel='rbf',
         kernel_params=None,
         param_grid=[{'kernel': ['linear'], 'degree': array([1, 2, 3])},
                      {'kernel': ['rbf'], 'gamma': array([ 0.1,  1. , 10. ])}],
         scoring=None, store_cv_scores=False)
Attributes:
cv_scores_ : array, shape = (n_samples, ~len(param_grid))

Cross-validation scores for each candidate parameter (if store_cv_scores=True and cv=None)

best_score_ : float

Mean cross-validated score of the best performing estimator.

n_splits_ : int

Number of cross-validation splits (folds/iterations)

Methods

fit(self, X, y[, sample_weight]) Fit Nadaraya Watson estimator.
get_params(self[, deep]) Get parameters for this estimator.
get_weights(self, X) Return model weights.
predict(self, X) Predict using the Nadaraya Watson model.
score(self, X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.
set_params(self, \*\*params) Set the parameters of this estimator.
__init__(self, param_grid, scoring=None, cv=None, store_cv_scores=False, kernel='linear', degree=3, coef0=1, gamma=None, kernel_params=None)[source]

Methods

__init__(self, param_grid[, scoring, cv, …])
fit(self, X, y[, sample_weight]) Fit Nadaraya Watson estimator.
get_params(self[, deep]) Get parameters for this estimator.
get_weights(self, X) Return model weights.
predict(self, X) Predict using the Nadaraya Watson model.
score(self, X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.
set_params(self, \*\*params) Set the parameters of this estimator.
fit(self, X, y, sample_weight=None)[source]

Fit Nadaraya Watson estimator.

Parameters:
X : array, shape (n_samples, n_features)

Training data.

y : array, shape (n_samples, n_features)

Target values.

Returns:
self : returns an instance of self