A complete end-to-end machine learning project for predicting house prices using Linear Regression on the real-world Kaggle Ames Housing Dataset, complete with a beautiful Streamlit web interface for deployment.
This project demonstrates a professional machine learning pipeline. It predicts house prices based on real-world features like above-ground living area, bedrooms, bathrooms, year built, overall material quality, and specific neighborhoods in Ames, Iowa.
-
Real-World Data: Utilizes the industry-standard Kaggle Ames Housing Dataset.
-
Robust Preprocessing Pipeline: Implements
scikit-learnPipelines withSimpleImputer,StandardScaler, andOneHotEncoderto handle missing values and categorical data automatically. -
Model Training: Linear Regression with strict training/testing splits to prevent data leakage.
-
Visualizations:
-
Correlation matrix
-
Feature distributions
-
Prediction plots
-
Feature importance
-
Interactive Web App: Streamlit interface with dynamic dropdowns and real-time predictions.
-
Model Persistence: Save and load the entire trained pipeline using Joblib.
-
Performance Metrics: R², RMSE, MAE, MSE.
house_price_prediction/
│
├── data/ # Data directory
│ └── train.csv # Kaggle Ames Housing Dataset
│
├── models/ # Saved models
│ ├── house_price_model.pkl # Trained ML Pipeline (Imputer + Scaler + Encoder + Model)
│ └── metrics.json # Model metrics
│
├── notebooks/ # Visualizations
│ ├── correlation_matrix.png
│ ├── feature_distributions.png
│ ├── predictions_plot.png
│ └── feature_importance.png
│
├── src/ # Source code
│ ├── preprocessing.py # Data preprocessing components
│ ├── model.py # Model training & evaluation
│ └── visualization.py # Plotting functions
│
├── train_model.py # Main training pipeline script
├── app.py # Streamlit web application
├── requirements.txt # Python dependencies
└── README.md # This file
- Python 3.8 or higher
- pip package manager
git clone https://github.com/Imhs14/House-Price-Prediction.git
cd House-Price-Prediction
pip install -r requirements.txt
Download train.csv from the Kaggle House Prices Competition and place it inside the data/ folder.
python train_model.py
This script will:
- Load the Kaggle dataset.
- Build and fit the preprocessing pipeline (imputation, scaling, encoding).
- Train the Linear Regression model.
- Evaluate performance on unseen test data.
- Save the entire pipeline and metrics.
streamlit run app.py
The web application will open in your browser (usually at http://localhost:8501).
Linear Regression - Mapped through a scikit-learn Pipeline to seamlessly handle raw input data directly from the user interface.
- GrLivArea - Above grade (ground) living area square feet
- BedroomAbvGr - Number of bedrooms above basement level
- FullBath - Full bathrooms above grade
- YearBuilt - Original construction date
- OverallQual - Overall material and finish quality (1-10)
- Neighborhood - Physical locations within Ames city limits (Categorical)
SalePrice - Property sale price in USD
- Missing Numeric Data: Imputed using the median strategy.
- Missing Categorical Data: Imputed using the most frequent strategy.
- Numeric Scaling:
StandardScalerfor normalization. - Categorical Encoding:
OneHotEncoderto translate text-based neighborhoods into machine-readable formats. - Train-Test Split: 80-20 split.
The model achieves realistic and strong performance on real-world housing data:
- R² Score: ~0.85 (explains 85% of variance in real-world prices)
- RMSE: ~$35,000
- MAE: ~$25,000
Note: These metrics reflect the natural noise and variance found in actual real estate markets, avoiding the overfitting commonly seen with synthetic datasets.
- Scikit-learn: Pipelines, Transformers, and Linear Regression
- Pandas: Data manipulation and ingestion
- NumPy: Numerical operations
- Plotly: Interactive charts and gauges
- Matplotlib / Seaborn: Statistical visualizations
- Streamlit: Web interface framework
- Joblib: Pipeline serialization
Based on real-world data analysis:
- Overall Quality and Living Area are the strongest predictors of sale price.
- Neighborhood plays a massive role in valuation, requiring categorical encoding to capture properly.
- Age (Year Built) shows a clear depreciation curve for older homes that haven't been remodeled.
- Add more advanced algorithms (Random Forest, XGBoost) to capture non-linear relationships.
- Expand the feature selection to include basement square footage and garage condition.
- Implement an automated hyperparameter tuning grid.
- Add data upload functionality for bulk predictions.
Feel free to fork this project and submit pull requests for improvements!
This project is open source and available for educational purposes.
Happy Predicting! 🏡💰*