Custom Estimator

You can combine your own learning algorithm, bet it a neural net or anything else, by simply adhering to the scikit-learn interface as shown below. Then register your class with the Register module and you're done!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
from sklearn.base import BaseEstimator, ClassifierMixin


class CustomEstimator(BaseEstimator, ClassifierMixin):

    def __init__(self, param1=0, param2=None):
        # it is important that you name your params the same in the constructor
        #  stub as well as in your class variables!
        self.param1 = param1
        self.param2 = param2

    def fit(self, X, y=None, **kwargs):
        """
        Adjust the underlying model or method to the data.

        Returns
        -------
        IMPORTANT: must return self!
        """
        return self

    def predict(self, X):
        """
        Use the learned model to make predictions.
        """
        return np.random.randint(0, 2, X.shape[0])