Inherit from scikit-learn's LassoCV model
<p>I tried to extend scikit-learn's RidgeCV model using inheritance:</p>

<pre><code>from sklearn.linear_model import RidgeCV, LassoCV

class Extended(RidgeCV):
    def __init__(self, *args, **kwargs):
        super(Extended, self).__init__(*args, **kwargs)

    def example(self):
        print 'Foo'


x = [[1,0],[2,0],[3,0],[4,0], [30, 1]]
y = [2,4,6,8, 60]
model = Extended(alphas = [float(a)/1000.0 for a in range(1, 10000)])
model.fit(x,y)
print model.predict([[5,1]])
</code></pre>

<p>It worked perfectly fine, but when I tried to inherit from LassoCV, it yielded the following traceback:</p>

<pre><code>Traceback (most recent call last):
  File "C:/Python27/so.py", line 14, in &lt;module&gt;
    model.fit(x,y)
  File "C:\Python27\lib\site-packages\sklearn\linear_model\coordinate_descent.py", line 1098, in fit
    path_params = self.get_params()
  File "C:\Python27\lib\site-packages\sklearn\base.py", line 214, in get_params
    for key in self._get_param_names():
  File "C:\Python27\lib\site-packages\sklearn\base.py", line 195, in _get_param_names
    % (cls, init_signature))
RuntimeError: scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). &lt;class '__main__.Extended'&gt; with constructor (&lt;self&gt;, *args, **kwargs) doesn't  follow this convention.
</code></pre>

<p>Can somebody explain how to fix this?</p>

<p>You probably want to make scikit-learn compatible model, to use it further with available scikit-learn functional. If you do - you need to read this first:
<a href="http://scikit-learn.org/stable/developers/contributing.html#rolling-your-own-estimator" rel="nofollow">http://scikit-learn.org/stable/developers/contributing.html#rolling-your-own-estimator</a></p>

<p>Shortly: scikit-learn has many features like estimator cloning (clone() function), meta algorithms like <code>GridSearch</code>, <code>Pipeline</code>, Cross validation. And all these things have to be able to get values of fields inside of your estimator, and change value of these fields (For example <code>GridSearch</code> has to change parameters inside of your estimator before each evaluation), like parameter <code>alpha</code> in <code>SGDClassifier</code>. To change value of some parameter it has to know its name. To get names of all fields in every classifier method <code>get_params</code> from <code>BaseEstimator</code> class (Which you're inheriting implicitly) requires all parameters to be specified in <code>__init__</code> method of a class, because it's easy to introspect all parameter names of <code>__init__</code> method (Look at <code>BaseEstimator</code>, this is the class which throws this error).</p>

<p>So it just wants you to remove all varargs like</p>

<pre><code>*args, **kwargs
</code></pre>

<p>from <code>__init__</code> signature. You have to list all parameters of your model in <code>__init__</code> signature, and initialise all internal fields of an object.</p>

<p>Here is example of <code>__init__</code> method of <a href="https://github.com/scikit-learn/scikit-learn/blob/412996f/sklearn/linear_model/stochastic_gradient.py#L548" rel="nofollow">SGDClassifier</a>, which is inherited from <code>BaseSGDClassifier</code>:</p>

<pre><code>def __init__(self, loss="hinge", penalty='l2', alpha=0.0001, l1_ratio=0.15,
             fit_intercept=True, n_iter=5, shuffle=True, verbose=0,
             epsilon=DEFAULT_EPSILON, n_jobs=1, random_state=None,
             learning_rate="optimal", eta0=0.0, power_t=0.5,
             class_weight=None, warm_start=False, average=False):
    super(SGDClassifier, self).__init__(
        loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio,
        fit_intercept=fit_intercept, n_iter=n_iter, shuffle=shuffle,
        verbose=verbose, epsilon=epsilon, n_jobs=n_jobs,
        random_state=random_state, learning_rate=learning_rate, eta0=eta0,
        power_t=power_t, class_weight=class_weight, warm_start=warm_start, average=average)
</code></pre>

python scikit-learn