sales / src /transformers.py
Amittripipathi's picture
Update src/transformers.py
1d1e6bb verified
raw
history blame contribute delete
905 Bytes
# 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'])
##