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

Class LinearRegression

source code

     object --+        
              |        
  BaseEstimator --+    
                  |    
RegressionEstimator --+
                      |
                     LinearRegression

Linear regression:

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

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

Parameters
----------
algorithm : ExplicitAlgorithm. The algorithm that should be used.
        Should be one of:
            1. GradientDescent(...)

        Default is GradientDescent(...).

algorithm_params : A dict. The dictionary algorithm_params contains
        parameters that should be set in the algorithm. Passing
        algorithm=GradientDescent(**params) is equivalent to passing
        algorithm=GradientDescent() and algorithm_params=params. Default
        is an empty dictionary.

start_vector : BaseStartVector. Generates the start vector that will be
        used.

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.gradient as gradient
>>>
>>> np.random.seed(42)
>>>
>>> n = 10
>>> p = 16
>>> X = np.random.rand(n, p)
>>> y = np.random.rand(n, 1)
>>> lr = estimators.LinearRegression(algorithm=gradient.GradientDescent(),
...                                  algorithm_params=dict(max_iter=1000),
...                                  mean=False)
>>> error = lr.fit(X, y).score(X, y)
>>> print "error = ", error
error =  0.0116466703591

Instance Methods [hide private]
 
__init__(self, algorithm=None, algorithm_params={}, start_vector=start_vectors.RandomStartVector(), 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, algorithm=None, algorithm_params={}, start_vector=start_vectors.RandomStartVector(), 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