Class ElasticNet
source code
object --+
|
BaseEstimator --+
|
RegressionEstimator --+
|
ElasticNet
Linear regression with L1 and L2 penalties. Represents the function:
f(beta, X, y) = (1 / (2 * n)) * ||X * beta - y||²_2
+ alpha * l * ||beta||_1
+ alpha * ((1.0 - l) / 2) * ||beta||²_2,
where ||.||²_2 is the squared L2-norm and ||.||_1 is the L1-norm.
Parameters
----------
l : Non-negative float. The Lagrange multiplier, or regularisation
constant, of the function.
alpha : Non-negative float. Scaling parameter of the regularisation.
Default is 1.
algorithm : ExplicitAlgorithm. The algorithm that should be applied.
Should be one of:
1. FISTA(...)
2. ISTA(...)
Default is FISTA(...).
algorithm_params : A dict. The dictionary algorithm_params contains
parameters that should be set in the algorithm. Passing
algorithm=FISTA(**params) is equivalent to passing
algorithm=FISTA() and algorithm_params=params. Default is
an empty dictionary.
start_vector : BaseStartVector. Generates the start vector that will be
used.
penalty_start : Non-negative integer. The number of columns, variables
etc., to be exempt from penalisation. Equivalently, the first
index to be penalised. Default is 0, all columns are included.
mean : Boolean. Whether to compute the squared loss or the mean squared
loss. Default is True, the mean squared loss.
Examples
--------
>>> import numpy as np
>>> import parsimony.estimators as estimators
>>> import parsimony.algorithms.proximal as proximal
>>> n = 10
>>> p = 16
>>>
>>> np.random.seed(42)
>>> X = np.random.rand(n, p)
>>> y = np.random.rand(n, 1)
>>> l = 0.1 # Regularisation coefficient
>>> en = estimators.ElasticNet(l,
... algorithm=proximal.FISTA(),
... algorithm_params=dict(max_iter=1000),
... mean=False)
>>> error = en.fit(X, y).score(X, y)
>>> print "error = ", round(error, 13)
error = 0.492096328053
|
__init__(self,
l,
alpha=1.0,
algorithm=None,
algorithm_params={ } ,
start_vector=start_vectors.RandomStartVector(),
penalty_start=0,
mean=True)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
|
|
|
|
score(self,
X,
y)
Returns the (mean) squared error of the estimator. |
source code
|
|
Inherited from RegressionEstimator :
predict
Inherited from BaseEstimator :
get_info ,
parameters ,
set_params
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
l,
alpha=1.0,
algorithm=None,
algorithm_params={ } ,
start_vector=start_vectors.RandomStartVector(),
penalty_start=0,
mean=True)
(Constructor)
| source code
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
- (inherited documentation)
|