This is a machine learning project where I built a model to predict the median house value of a district using the California Housing dataset.
I wanted to understand the complete workflow of a regression problem instead of just training a model, so the project includes data splitting, preprocessing, model comparison, cross-validation, and finally using the trained model to make predictions.
What I used
Python
Pandas
NumPy
Scikit-learn
Joblib
Dataset
The dataset contains information about different housing districts in California, including:
Median income
Housing median age
Average number of rooms
Average number of bedrooms
Population
Average household size
Ocean proximity
Latitude and longitude
The target variable is median_house_value.
How the project works
1. Train-Test Split
I used StratifiedShuffleSplit to divide the dataset into training and testing data.
I created an income_cat column based on median_income so that the income distribution remains similar in both sets.
2. Data Preprocessing
For numerical features, I used:
Median imputation for missing values
Standard scaling
For the categorical ocean_proximity feature, I used one-hot encoding.
I combined these using Scikit-learn's Pipeline and ColumnTransformer.
3. Models
I tested three different regression models:
Linear Regression
Decision Tree Regressor
Random Forest Regressor
I used 10-fold cross-validation and RMSE to compare their performance.
Results
Model
Mean RMSE
Linear Regression
$69,070.52
Decision Tree
$69,015.14
Random Forest
$49,199.35
Lower RMSE means better performance, so Random Forest performed the best.
It reduced the RMSE by around 28.8% compared with Linear Regression, which made it the model I chose for the final prediction system.
Model Saving & Prediction
After choosing Random Forest, I saved both the trained model and preprocessing pipeline using Joblib: