Spaces:
Runtime error
Runtime error
Download custom.py from radwaamr1/DesertificationClassification-API: direct link, hf CLI and curl.
- Browser
- Download file 630 Bytes
-
https://huggingface.co/spaces/radwaamr1/DesertificationClassification-API/resolve/main/custom.py
- Command line
-
hf download hf://spaces/radwaamr1/DesertificationClassification-API/custom.py
-
curl -L -o custom.py https://huggingface.co/spaces/radwaamr1/DesertificationClassification-API/resolve/main/custom.py
630 Bytes
| # custom.py | |
| import numpy as np | |
| from sklearn.base import BaseEstimator, TransformerMixin | |
| class FeatureFilter(BaseEstimator, TransformerMixin): | |
| def __init__(self, expected_features): | |
| self.expected_features = expected_features | |
| def fit(self, X, y=None): | |
| return self | |
| def transform(self, X): | |
| X = X.copy() | |
| # Keep only expected features | |
| X = X[[c for c in self.expected_features if c in X.columns]] | |
| # Add missing features as NaN | |
| for c in self.expected_features: | |
| if c not in X.columns: | |
| X[c] = np.nan | |
| return X[self.expected_features] | |