This project predicts housing prices in Singapore using Linear Regression. Two methods are implemented for training the model:
- Normal Equation: Directly calculates the best-fitting weights using a closed-form solution.
- Gradient Descent: Iteratively updates weights to minimize the mean squared error.
The project provides step-by-step implementation of linear regression algorithms, including data preprocessing, model training, and evaluation metrics such as Mean Squared Error (MSE) and Mean Absolute Error (MAE).
The dataset housing_data.csv consists of 90 housing data points. Each data point includes:
- floor_area_sqm - The size of the house in square meters (used as the primary feature for prediction).
- bedrooms - Number of bedrooms in the house.
- schools - Number of primary schools within a 1 km radius.
- asking_price - The price of the housing unit (used as the target variable).
- Predict housing prices using a linear regression model.
- Compare two methods for solving linear regression:
- Normal Equation: Computes optimal weights directly using a mathematical formula.
- Gradient Descent: Iteratively updates weights to minimize prediction error.
- Evaluate the model using MSE (Mean Squared Error) and MAE (Mean Absolute Error).
- Visualize model predictions against the actual data to assess performance.
- Clone the repository:
git clone https://github.com/your-username/Housing-Prices-Prediction.git
cd SG-HousePrice-Predictor
- Install dependencies using pip:
pip install -r requirements.txt
- Run the main script:
python main.py
- The output will display the model results.
Unit tests are provided to validate the implementation of the gradient descent algorithm and other utilities. Run the tests using pytest:
pytest tests/
A sample plot using floor_area_sqm as the only feature comparing the actual housing prices with model predictions. Blue points represent the actual data. Red line represents predictions using the Normal Equation. Green line represents predictions using Gradient Descent.