File size: 905 Bytes
1d1e6bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
# transformers.py
from sklearn.base import BaseEstimator, TransformerMixin

class SugarContentReplacer(BaseEstimator, TransformerMixin):
    def fit(self, X, y=None):
        return self

    def transform(self, X):
        X = X.copy()
        X['Product_Sugar_Content'] = X['Product_Sugar_Content'].replace('reg', 'Regular')
        return X

    def get_feature_names_out(self, input_features=None):
        if input_features is None:
            return ['Product_Sugar_Content']
        else:
            return input_features

##
class StoreAgeCalculator(BaseEstimator, TransformerMixin):
    def __init__(self):
        self.current_year = datetime.now().year

    def fit(self, X, y=None):
        return self

    def transform(self, X):
        X = X.copy()
        X['Store_Age'] = self.current_year - X['Store_Establishment_Year']
        return X.drop(columns=['Store_Establishment_Year'])

##