mutar.IndRewLasso

class mutar.IndRewLasso(alpha=1.0, fit_intercept=True, normalize=False, max_iter=2000, max_iter_reweighting=100, tol=0.0001, positive=False, warm_start=False)[source]

Independent Reweighted Lasso estimator with L1 regularizer.

The optimization objective for IndRewLasso is:

(1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_0.5

Where:

||W||_0.5 = sum_i sum_j sqrt|w_ij|
Parameters
alpha(float or array-like), shape (n_tasks)

Optional, default ones(n_tasks) Constant that multiplies the L0.5 term. Defaults to 1.0

fit_interceptboolean

whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalizeboolean

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm.

max_iterint, optional

The maximum number of inner loop iterations

max_iter_reweightingint, optional

Maximum number of reweighting steps i.e outer loop iterations

tolfloat, optional

The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

positiveboolean, optional (default False)

If True, coefficients are constrained to be non-negative.

warm_startbool, optional

When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.

Examples

>>> from mutar import IndRewLasso
>>> import numpy as np
>>> X = np.array([[[3, 1], [2, 0], [1, 0]],                     [[0, 2], [-1, 3], [1, -2]]], dtype=float)
>>> coef = np.array([[1., 1.], [0., -1]])
>>> y = np.array([x.dot(c) for x, c in zip(X, coef.T)])
>>> y += 0.1
>>> alpha = [0.1, 0.2]
>>> relasso = IndRewLasso(alpha=alpha).fit(X, y)
>>> print(relasso.coef_)
[[ 0.92188134  0.        ]
 [ 0.         -1.33862186]]
Attributes
coef_array, shape (n_features, n_tasks)

Parameter vector (W in the cost function formula).

intercept_array, shape (n_tasks,)

independent term in decision function.

n_iter_int

number of iterations run by the coordinate descent solver to reach the specified tolerance.

__init__(self, alpha=1.0, fit_intercept=True, normalize=False, max_iter=2000, max_iter_reweighting=100, tol=0.0001, positive=False, warm_start=False)[source]

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

Methods

__init__(self[, alpha, fit_intercept, …])

Initialize self.

fit(self, X, y)

get_params(self[, deep])

Get parameters for this estimator.

predict(self, X)

Predict target given unseen data samples.

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.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

predict(self, X)

Predict target given unseen data samples.

Parameters
X{array-like}, shape (n_tasks, n_samples, n_features)

The training input samples.

Returns
yndarray, shape (n_tasks, n_samples)

Returns the predicted targets.

score(self, X, y, sample_weight=None)

Returns the coefficient of determination R^2 of the prediction.

Computes a score for each regression task. The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters Xarray-like, shape = (n_tasks, n_samples, n_features) Test samples.

yarray-like, shape = (n_tasks, n_samples) True values for y.

sample_weightarray-like, shape = [n_tasks, n_samples], optional Sample weights.

Returns
array-like, shape = (n_tasks)
R^2 of self.predict(X) wrt. y for each task.
set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self