Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Implements a *transform* which follows the smae API
5as every :epkg:`scikit-learn` transform.
6"""
7from .sklearn_base import SkBase
10class SkBaseTransform(SkBase):
11 """
12 Pattern of a *learner* which follows the same API que :epkg:`scikit-learn`.
13 """
15 def __init__(self, **kwargs):
16 """
17 Stores the parameters.
18 """
19 SkBase.__init__(self, **kwargs)
21 ###################
22 # API scikit-learn
23 ###################
25 def fit(self, X, y=None, **kwargs):
26 """
27 Trains a model.
29 @param X features
30 @param y targets
31 @return self
32 """
33 raise NotImplementedError()
35 def transform(self, X):
36 """
37 Transforms the data.
39 @param X features
40 @return predictions
41 """
42 raise NotImplementedError()
44 def fit_transform(self, X, y=None, **kwargs):
45 """
46 Trains and transforms the data.
48 @param X features
49 @param y targets
50 @return self
51 """
52 self.fit(X, y=y, **kwargs)
53 return self.transform(X)