<p>Full instructions are available in the <a href="http://scikit-learn.org/stable/developers/contributing.html#rolling-your-own-estimator" rel="noreferrer">scikit-learn docs</a>, and the principles behind the API are set out in <a href="http://arxiv.org/abs/1309.0238" rel="noreferrer">this paper by yours truly et al.</a> In short, besides <code>fit</code>, what you need for an estimator are <code>get_params</code> and <code>set_params</code> that return (as a <code>dict</code>) and set (from kwargs) the hyperparameters of the estimator, i.e. the parameters of the learning algorithm itself (as opposed to the data parameters it learns). These parameters should match the <code>__init__</code> parameters.</p>

<p>Both methods can be obtained by inheriting from the classes in <code>sklearn.base</code>, but you can provide them yourself if you don't want your code to be dependent on scikit-learn.</p>

<p>Note that input validation should be done in <code>fit</code>, not the constructor, because otherwise you can still set invalid parameters in <code>set_params</code> and have <code>fit</code> fail in unexpected ways.</p>
What's the full specification for implementing a custom scikit-learn estimator?
<p>I'm rolling my own predictor and want to use it like I would use any of the scikit routines (e.g. RandomForestRegressor). I have a class containing <code>fit</code> and <code>predict</code> methods that seem to work fine. However, when I try to use some of the scikit methods, such as cross validation, I get errors like:</p>

<pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Python27\lib\site-packages\sklearn\cross_validation.py", line 1152, in cross_val_
score
    for train, test in cv)
  File "C:\Python27\lib\site-packages\sklearn\externals\joblib\parallel.py", line 516, in __
call__
    for function, args, kwargs in iterable:
  File "C:\Python27\lib\site-packages\sklearn\cross_validation.py", line 1152, in &lt;genexpr&gt;
    for train, test in cv)
  File "C:\Python27\lib\site-packages\sklearn\base.py", line 43, in clone
    % (repr(estimator), type(estimator)))
TypeError: Cannot clone object '&lt;__main__.Custom instance at 0x033A6990&gt;' (type &lt;type 'inst
ance'&gt;): it does not seem to be a scikit-learn estimator a it does not implement a 'get_para
ms' methods.
</code></pre>

<p>I see that it wants me to implement some methods (presumably <code>get_params</code> as well as maybe <code>set_params</code> and <code>score</code>) but I'm not sure what the right specification for making these methods is. Is there some information available on this topic? Thanks.</p>