fromsklearn.baseimportBaseEstimator,TransformerMixinclassMyTransformer(BaseEstimator,TransformerMixin):def__init__(self,first_paramter=1,second_parameter=2):# all parameters must be specified in the __init__ functionself.first_paramter=1self.second_parameter=2deffit(self,X,y=None):# fit should only take X and y as parameters# even if your model is unsupervised, you need to accept a y argument!# Model fitting code goes hereprint("fitting the model right here")# fit returns selfreturnselfdeftransform(self,X):# transform takes as parameter only X# apply some transformation to X:X_transformed=X+1returnX_transformed
Where to go from here
Theory
Other machine learning frameworks and packages
Ranking, recommender systems, time series, and other kinds of learning
Probabilistic modeling, inference and probabilistic programming