This project is a House Price Prediction Application developed for a final year project. It uses machine learning to predict house prices based on user input. The application has a React.js frontend and a Flask backend, which uses a pre-trained machine learning model.
- Predict house prices based on input features such as bedrooms, bathrooms, and house condition.
- Modern and responsive user interface built with React.js.
- Scalable Flask API that serves predictions from a pre-trained model.
- Easily deployable on localhost for testing and demonstrations.
model/
: Contains the trained machine learning model (house_price_model.pkl
) and the scaler (scaler.pkl
).notebook/
: Jupyter notebooks used for training the machine learning model.app.py
: Flask application that serves as the API.requirements.txt
: List of dependencies needed for the backend.
public/
: Public assets for the React application.src/
: Source files for the React application.App.js
: Main component handling the UI.components/
: Reusable components.
package.json
: Configuration file listing dependencies and scripts for the frontend.
Make sure you have Git installed on your system. Open your terminal and run:
git clone https://github.com/Rishiraj8/house_prediction.git
cd House
-
Navigate to the backend folder:
cd backend
-
Create and activate a Python virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install the required Python dependencies:
pip install -r requirements.txt
-
Start the Flask server:
python app.py
- The Flask server will now run on
http://127.0.0.1:5000
(localhost). - Keep this terminal running.
- The Flask server will now run on
-
Open a new terminal and navigate to the frontend folder:
cd frontend
-
Install the required Node.js dependencies:
npm install
-
Start the React development server:
npm run dev
- The React app will now run on
http://127.0.0.1:5173
(localhost). - Keep this terminal running.
- The React app will now run on
- Open your browser and go to
http://127.0.0.1:5173
. - Enter the required details in the form (e.g., number of bedrooms, bathrooms, etc.).
- Click the Predict Price button.
- The predicted house price will be displayed on the screen.
- Ensure both the Flask backend and React frontend are running simultaneously.
- If you encounter issues, check the terminal logs for errors.
- You can modify the machine learning model or retrain it using the Jupyter notebook in the
notebook/
folder.
-
Dataset:
- The model was trained using a dataset (
house_data.csv
) containing features related to house properties and their respective prices.
- The model was trained using a dataset (
-
Features Used:
- Number of bedrooms
- Number of bathrooms
- Living area (in square feet)
- Condition of the house (scaled from 1 to 5)
- Number of schools nearby
-
Target Variable:
- Price: The dependent variable representing the house price.
-
Data Preprocessing:
- The feature variables were scaled using
StandardScaler
to normalize the data. This ensures that features with varying magnitudes do not disproportionately influence the model.
- The feature variables were scaled using
-
Model Used:
- Random Forest Regressor: A machine learning ensemble model that uses multiple decision trees to predict the target variable.
- Key Parameters:
n_estimators=100
: The model uses 100 decision trees for making predictions.random_state=42
: Ensures reproducibility of results.
- Why Random Forest:
- Handles non-linear relationships well.
- Resistant to overfitting when tuned properly.
- Capable of handling feature importance, making it suitable for regression tasks like house price prediction.
- Key Parameters:
- Random Forest Regressor: A machine learning ensemble model that uses multiple decision trees to predict the target variable.
-
Model Evaluation:
- R² Score (Coefficient of Determination):
- Training R² Score: Measures how well the model fits the training data.
- Testing R² Score: Indicates the model's predictive performance on unseen data.
- R² Score (Coefficient of Determination):
-
Model Saving:
- The trained model (
house_price_model.pkl
) and the scaler (scaler.pkl
) were serialized and saved for future use. These files are located in thebackend\model
directory.
- The trained model (
This project was developed as a final year project for a school friend of mine.