mcmodels.regressors.NonnegativeLinear

class mcmodels.regressors.NonnegativeLinear[source]

Nonnegative least squares linear model.

This model solves a regression model where the loss function is the nonnegative linear least squares function. This estimator has built-in support for mulitvariate regression.

Examples

>>> import numpy as np
>>> from mcmodels.regressors import NonnegativeLinear
>>> # 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 = NonnegativeLinear()
>>> reg.fit(X, y)
NonnegativeLinear()
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.
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, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Methods

fit(self, X, y[, sample_weight]) Fit nonnegative least squares linear model.
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.

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.