File size: 851 Bytes
72bce8e
1ff2e82
72bce8e
 
 
1ff2e82
72bce8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ff2e82
 
 
 
72bce8e
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

# FeatureEngineering.py
from sklearn.base import BaseEstimator, TransformerMixin
import numpy as np
import pandas as pd

class FeatureEngineering(BaseEstimator, TransformerMixin):
    def __init__(self):
        pass

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

    def transform(self, X):
        X_ = X.copy()
        X_['StaffRatio'] = X_['StaffOnline'] / X_['StaffEmployed']
        X_['TotalArea'] = X_['StoreArea'] + X_['PickingArea']
        X_['Year'] = X_['Date'].dt.year
        X_['Month'] = X_['Date'].dt.month
        X_['Weekday'] = X_['Date'].dt.weekday
        X_['SlotHour'] = X_['Slot'].str.split(":").str[0].astype(int)

        # Keep categorical SpecialEvent as-is, and also add an indicator if needed
        X_['IsSpecialEvent'] = X_['SpecialEvent'].apply(lambda x: 0 if pd.isna(x) or x == "" else 1)

        return X_