Download model_classes.py from PR118/SalesForecastPrediction-BackendNEW: direct link, hf CLI and curl.
- Browser
- Download file 636 Bytes
-
https://huggingface.co/spaces/PR118/SalesForecastPrediction-BackendNEW/resolve/main/model_classes.py
- Command line
-
hf download hf://spaces/PR118/SalesForecastPrediction-BackendNEW/model_classes.py
-
curl -L -o model_classes.py https://huggingface.co/spaces/PR118/SalesForecastPrediction-BackendNEW/resolve/main/model_classes.py
636 Bytes
| from sklearn.base import BaseEstimator, TransformerMixin | |
| import pandas as pd | |
| class ProductTypeCategorizer(BaseEstimator, TransformerMixin): | |
| def __init__(self): | |
| self.perishables = [ | |
| "Dairy", | |
| "Meat", | |
| "Fruits and Vegetables", | |
| "Breakfast", | |
| "Breads", | |
| "Seafood", | |
| ] | |
| def fit(self, X, y=None): | |
| return self | |
| def transform(self, X): | |
| X = X.copy() | |
| X = pd.Series(X.squeeze()) # ensure 1D | |
| return pd.DataFrame( | |
| X.apply(lambda x: "Perishables" if x in self.perishables else "Non Perishables") | |
| ) | |