title: Create custom Regressor in sklearn
body: <p>I would like to use a custom Regressor with <code>sklearn</code> <code>GridSearchCV</code>. The spirit of it is analogous to creating a custom Classifier - as shown in this blog:</p>
  
  <p><a href="http://danielhnyk.cz/creating-your-own-estimator-scikit-learn/" rel="nofollow noreferrer">http://danielhnyk.cz/creating-your-own-estimator-scikit-learn/</a></p>
  
  <p>Here is a condensed/edited portion of the code from the blog - showing some of the required methods to override. </p>
  
  <pre><code>from sklearn.base import BaseEstimator, RegressorMixin
  
  class MyCustomClassifier(BaseEstimator, RegressorMixin):  
      """An example of classifier"""
  
      def __init__(self, intValue=0, stringParam="defaultValue", otherParam=None):
          """
          Called when initializing the classifier
          """
          self.intValue = intValue
          self.stringParam = stringParam
  
      def fit(self, X, y=None):
          self.treshold_ = (sum(X)/len(X)) + self.intValue  # mean + intValue
  
          return self
  
      def _meaning(self, x):
          # returns True/False according to fitted classifier
          # notice underscore on the beginning
          return( True if x &gt;= self.treshold_ else False )
  
      def predict(self, X, y=None):
           ..
  </code></pre>
  
  <p>The things that would be <em>same</em> between Regressor and Classifier would likely be the <code>__init__, fit, predict</code> methods: I can probably piece that much together. But what about equivalents to <code>__meaning</code> ? Or other subtle considerations for a <code>Regressor</code> that might not be obvious/clear?</p>
  
  <p>Here is a skeleton I am starting with:</p>
  
  <pre><code>from sklearn.base import BaseEstimator, RegressorMixin
  class MyCustomRegressor(BaseEstimator, RegressorMixin):
      def __init__(self, regressorMethod):
        self.regressorMethod = regressorMethod
  
      def fit(self, X, y=None):
        self.regressorMethod(X,y)
        return self
  </code></pre>
  
  <p>It is my understanding that the <code>score</code> method will be used by GridSearchCv ..?</p>