Hide keyboard shortcuts

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 

8 

9 

10class SkBaseTransform(SkBase): 

11 """ 

12 Pattern of a *learner* which follows the same API que :epkg:`scikit-learn`. 

13 """ 

14 

15 def __init__(self, **kwargs): 

16 """ 

17 Stores the parameters. 

18 """ 

19 SkBase.__init__(self, **kwargs) 

20 

21 ################### 

22 # API scikit-learn 

23 ################### 

24 

25 def fit(self, X, y=None, **kwargs): 

26 """ 

27 Trains a model. 

28 

29 @param X features 

30 @param y targets 

31 @return self 

32 """ 

33 raise NotImplementedError() 

34 

35 def transform(self, X): 

36 """ 

37 Transforms the data. 

38 

39 @param X features 

40 @return predictions 

41 """ 

42 raise NotImplementedError() 

43 

44 def fit_transform(self, X, y=None, **kwargs): 

45 """ 

46 Trains and transforms the data. 

47 

48 @param X features 

49 @param y targets 

50 @return self 

51 """ 

52 self.fit(X, y=y, **kwargs) 

53 return self.transform(X)