mcmodels.regressors.NonnegativeRidge

class mcmodels.regressors.NonnegativeRidge(alpha=1.0, solver='SLSQP', **solver_kwargs)[source]

Nonnegative least squares with L2 regularization.

This model solves a regression model where the loss function is the nonnegative linear least squares function and regularization is given by the l2-norm. This estimator has built-in support for mulitvariate regression.

Parameters:
alpha : float or array with shape = (n_features,)

Regularization strength; must be a positive float. Improves the conditioning of the problem and reduces the variance of the estimates. Larger values specify stronger regularization.

solver : string, optional (default = ‘SLSQP’)

Solver with which to solve the QP. Must be one that supports bounds (i.e. ‘L-BFGS-B’, ‘TNC’, ‘SLSQP’).

**solver_kwargs

See scipy.optimize.minimize for valid keyword arguments

Notes

Examples

>>> import numpy as np
>>> from mcmodels.regressors import NonnegativeRidge
>>> # 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
>>> reg = NonnegativeRidge(alpha=1.0)
>>> reg.fit(X, y)
NonnegativeRidge(alpha=1.0)
Attributes:
coef_ : array, shape = (n_features,) or (n_features, n_targets)

Weight vector(s).

res_ : float

The residual, of the nonnegative least squares fitting.

Methods

fit(self, X, y[, sample_weight]) Fit nonnegative least squares linear model with L2 regularization.
get_params(self[, deep]) Get parameters for this estimator.
predict(self, X) Predict using the linear 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, alpha=1.0, solver='SLSQP', **solver_kwargs)[source]

Methods

__init__(self[, alpha, solver])
fit(self, X, y[, sample_weight]) Fit nonnegative least squares linear model with L2 regularization.
get_params(self[, deep]) Get parameters for this estimator.
predict(self, X) Predict using the linear 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 nonnegative least squares linear model with L2 regularization.

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

Training data.

y : array, shape = (n_samples,) or (n_samples, n_targets)

Target values.

sample_weight : float or array-like, shape (n_samples,), optional (default = None)

Individual weights for each sample.

Returns:
self : returns an instance of self.