https://github.com/bala179/housing-prices-prediction
A small project to predict housing prices by training against a sample dataset.
https://github.com/bala179/housing-prices-prediction
data-science machine-learning regression
Last synced: 11 months ago
JSON representation
A small project to predict housing prices by training against a sample dataset.
- Host: GitHub
- URL: https://github.com/bala179/housing-prices-prediction
- Owner: Bala179
- Created: 2021-04-18T17:36:24.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-19T13:11:05.000Z (about 5 years ago)
- Last Synced: 2025-05-03T17:37:29.279Z (about 1 year ago)
- Topics: data-science, machine-learning, regression
- Language: Jupyter Notebook
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Predicting Housing Prices
This is my first ML project, which uses the simple 'boston' dataset in sklearn and aims to build a model to predict housing prices from the data in this dataset.
## Loading Data
Data is first loaded using the `load_boston()` method in `sklearn.datasets` and converted to a pandas DataFrame. The contents of the dataset are examined using the `head()` function and it is also checked for missing values (in this case there are none). Then the features and the target variable (in this case, MEDV - the median value of owner-occupied homes in $1000’s) are then separated.
## Training the models
The estimators that I have used have made use of *pipelines*, that is, estimators making use of a number of sub-steps chained together. This makes it possible to use the new, compund, estimator in cross-validation (remember that, if you are scaling the data, you would need to fit the scaler on the *training data* only, this can be done in cross-validation using a pipeline). I tried 3 different models to make predictions - linear regression, polynomial ridge regression and support vector regression. In the last 2 models I used `GridSearchCV` with 5 folds to find the best set of parameters - additionally, I had to perform a train-test split for these 2 cases, so that a portion of unseen data is available for testing the model at the end. Since linear regression has no hyperparameters to tune, I simply used `cross_val_score()` with 5 folds to fit and evaluate the model, without any train-test splitting. (Note: Because of shuffling in the K-Fold cross-validation, the results of the program may vary.)
The scoring metric which I used is R2, which should be as close to 1 as possible for a good fit to the data. In the first case, the mean R2 was evaluated by taking the mean of the 5 cross-validation scores; in the other 2 cases, it was evaluated using the best found parameter(s) on the unseen test data.
# Conclusion
None of the models got a perfect R2 of 1; however, the best score (among the 3 models) of around 0.85 was found for **polynomial ridge regression with alpha = 3 and degree of polynomial = 2** (in one execution of the program - the result may vary if it is run again).