Package parsimony :: Module estimators :: Class RidgeRegression
[hide private]
[frames] | no frames]

Class RidgeRegression

source code

     object --+        
              |        
  BaseEstimator --+    
                  |    
RegressionEstimator --+
                      |
                     RidgeRegression

Linear regression with an L2 penalty. Represents the function:

    f(beta, X, y) = (1 / (2 * n)) * ||X * beta - y||²_2
                  + (l / 2) * ||beta||²_2,

where ||.||²_2 is the squared L2-norm.

Parameters
----------
l : Non-negative float. The L2 regularisation parameter.

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.618  # Regularisation coefficient
>>> rr = estimators.RidgeRegression(l,
...                                 algorithm=proximal.FISTA(),
...                                 algorithm_params=dict(max_iter=1000),
...                                 mean=False)
>>> error = rr.fit(X, y).score(X, y)
>>> print "error = ", error
error =  0.377679437659

Instance Methods [hide private]
 
__init__(self, l, 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
 
get_params(self)
Return a dictionary containing the estimator's parameters.
source code
 
fit(self, X, y, beta=None)
Fit the estimator to the data.
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__

Class Variables [hide private]
  __abstractmethods__ = frozenset([])

Inherited from RegressionEstimator: __metaclass__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, l, 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)

get_params(self)

source code 

Return a dictionary containing the estimator's parameters.

Overrides: BaseEstimator.get_params

fit(self, X, y, beta=None)

source code 

Fit the estimator to the data.

Overrides: BaseEstimator.fit

score(self, X, y)

source code 

Returns the (mean) squared error of the estimator.

Overrides: BaseEstimator.score