Download src/features/build_features.py from servisgas/pricing: direct link, hf CLI and curl.
- Browser
- Download file 962 Bytes
-
https://huggingface.co/spaces/servisgas/pricing/resolve/main/src/features/build_features.py
- Command line
-
hf download hf://spaces/servisgas/pricing/src/features/build_features.py
-
curl -L -o build_features.py https://huggingface.co/spaces/servisgas/pricing/resolve/main/src/features/build_features.py
962 Bytes
| import pandas as pd | |
| from src.features.geo_features import LondonPropertyGeoFeatures | |
| # Optional: | |
| # from src.features.feature_engineering import add_non_geo_features | |
| # from src.features.nlp_features import PropertyTextEncoder | |
| def is_numeric_and_true(value): | |
| return isinstance(value, (int, float)) and bool(value) | |
| def build_features(df: pd.DataFrame, geo_dir: str = "data/geo") -> pd.DataFrame: | |
| """ | |
| Compute all features used by the rent price model. | |
| Combines geospatial, engineered, and NLP-derived features. | |
| """ | |
| # 1. Geospatial engineered features | |
| geo = LondonPropertyGeoFeatures(geo_dir) | |
| df = geo.add_features_to_df(df) | |
| # 2. Other engineered features (optional) | |
| # df = add_non_geo_features(df) | |
| # 3. NLP / embeddings (optional) | |
| # encoder = PropertyTextEncoder() | |
| # df = encoder.add_nlp_embeddings(df, text_column="description") | |
| df["deposit"] = df["deposit"].apply(is_numeric_and_true) | |
| return df | |