A production-ready machine learning repository demonstrating end-to-end data pipelines, advanced feature engineering, model serialization, and interactive deployment.
Explore the deployed system live on Hugging Face Spaces:
👉 Launch the Live Property Estimator Space
This project demonstrates software engineering best practices for data science, ensuring a clean separation of concerns by separating training pipelines (train.py) from serving applications (app.py), and pre-serializing models to optimize sub-second online inference.
graph TD
A[California Census CSV Dataset] -->|1. Data Cleaning| B(Drop Missing Values)
B -->|2. Feature Engineering| C[Log Transforms & Custom Ratios]
C -->|3. Feature Scaling| D(StandardScaler Fit & Transform)
D -->|4. Training| E[Multi-Variable Linear Regression]
E -->|5. Serialization| F[Export model.pkl, scaler.pkl, columns.pkl]
F -->|6. Production Serving| G[app.py Streamlit UI Engine]
H[User Real-time Inputs] -->|7. Preprocess & Scale| G
G -->|8. High-Speed Inference| I[Estimated Property Value Display]
-
Logarithmic Smoothing: Census features like
total_rooms,total_bedrooms,population, andhouseholdsexhibit severe right-skewness. Applying$y = \log(x + 1)$ normalizes the distribution, ensuring the Linear Regression model handles outliers robustly. -
Domain-Specific Ratios:
-
bedroom_ratio($\frac{\text{total bedrooms}}{\text{total rooms}}$ ): Helps capture the density of bedrooms, which highly correlates with house style and density. -
household_rooms($\frac{\text{total rooms}}{\text{households}}$ ): Captures the average room scale per housing unit.
-
-
Categorical Categorization: One-hot encodes
ocean_proximityto enable numerical model coefficients for geographical locations.
Rather than training the model dynamically on every single API/page request, this system pre-serializes the trained LinearRegression model and StandardScaler state as .pkl binary files.
- Latency Advantage: Drops model load time to <1ms, compared to training on-the-fly which takes several seconds and burdens CPU resources.
- Reliability: Built with an elegant dual fallback structure: loads local
.pklfiles first, with an automated fallback to train on-the-fly from GitHub or local CSV if artifacts are missing.
- R² Score (Coefficient of Determination): 0.6520 (Explains 65.2% of the variance in California property values)
- Mean Absolute Error (MAE): $49,852
- Root Mean Squared Error (RMSE): $68,340
The model uncovers critical econometric insights based on standard census data:
| Feature | Coefficient Sign | Economic Interpretation |
|---|---|---|
| Median Income | 🟢 Positive (Strongest) | Higher neighborhood income is the most powerful driver of home valuation. |
| Inland Location | 🔴 Negative (Strongest) | Properties situated inland suffer a massive valuation discount compared to coastal areas. |
| Near Ocean / Near Bay | 🟢 Positive (Moderate) | Coastline proximity yields a substantial valuation premium. |
| Bedroom Ratio | 🔴 Negative (Moderate) | Higher bedroom density (e.g. apartment blocks) indicates lower single-family premium pricing. |
House_Predicition_Values/
│
├── train.py # Offline Model training, evaluation & serialization pipeline
├── app.py # High-performance Streamlit UI & inference serving logic
├── requirements.txt # Package dependencies with compatible pins
├── README.md # Premium developer and recruiter documentation
├── housing.csv # California Housing Census source dataset
│
├── models/ # Serialized Production Artifacts
│ ├── model.pkl # Serialized Scikit-learn Linear Regression model
│ ├── scaler.pkl # Serialized StandardScaler state
│ └── columns.pkl # Exported trained feature schema alignment
│
├── notebooks/ # Research & Prototyping
│ └── california_housing_analysis.ipynb # Exploratory Data Analysis & training log
│
└── media/ # Portfolio Assets
├── House hold Screenshot.png # Interactive GIS Web App screenshot
└── house_prediction_demo.mp4 # HD Video application walk-through
Follow these steps to run the training pipeline and launch the web interface locally:
git clone https://github.com/bilalahmed251/House_Predicition_Values.git
cd House_Predicition_Values# Windows
python -m venv venv
venv\Scripts\activate
# macOS / Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtTo retrain the model and regenerate the .pkl files inside models/:
python train.pystreamlit run app.pyThe application will boot up at http://localhost:8501/ with live hot-reloading.
This app is optimized for serverless hosting on Hugging Face Spaces (using the Streamlit SDK):
- Create a new Streamlit Space on Hugging Face.
- Push
app.py,requirements.txt,housing.csv, and the pre-trainedmodels/folder. - Hugging Face automatically spins up the instance and serves the property valuation engine.
