Coverage for mlinsights/sklapi/sklearn_base_transform.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-09 08:45 +0200

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)