- This project is a web application that predicts the fare of a flight based on various input features provided by the user. The application is built using Flask for the backend and employs a Random Forest model for the prediction, which has been trained on historical flight data
- Home Page : A form for users to input flight details (departure time, arrival time, stops, airline, source, destination).
- Prediction Page : Displays the predicted flight fare based on the user inputs.
- Flask Application : Handles HTTP requests, processes user inputs, interacts with the database, and returns predictions.
- Prediction Model : A pre-trained Random Forest model serialized using pickle.
- Database : Stores user inputs and prediction results.
- Predicts flight fare based on user inputs.
- User inputs include date and time of journey, departure and arrival times, number of stops, airline, source, and destination.
- Utilizes a pre-trained Random Forest model for accurate predictions.
- User Input: The user provides details about their journey through a web form, including:
- Date and time of departure and arrival
- Number of stops
- Airline
- Source and destination
- Data Processing: The application processes the input data:
- Extracts day and month from the date of journey
- Extracts hours and minutes from the departure and arrival times
- Calculates the duration of the flight in hours and minutes
- Encodes categorical features such as airline, source, and destination
-
Model Prediction: The processed data is fed into the pre-trained Random Forest model to predict the flight fare.
-
Output: The predicted fare is displayed to the user on the web page.
- Flask : A lightweight WSGI web application framework in Python.
- Scikit-Learn : A machine learning library in Python, used for building and training the Random Forest model.
- Pandas : A data manipulation library in Python, used for data processing.
- NumPy : A library for numerical computations in Python, used for handling arrays.
- HTML/CSS : For designing the web interface.
- Flask-CORS : To handle Cross-Origin Resource Sharing (CORS).
- app.py: The main Flask application file.
- model/flight_rf.pkl: The pre-trained Random Forest model serialized using pickle.
- templates/home.html: The HTML template for the home page.
- home() : Renders the home page with the input form.
- predict() : Handles form submission, processes inputs, makes predictions, stores data in the database, and renders the result.
- process_input() : Extracts and processes date, time, and categorical features from user inputs.
- make_prediction() : Uses the pre-trained model to predict the flight fare.
- store_data() : Stores user inputs and prediction result in the database.
- home.html : The HTML template for the home page, containing the input form and displaying the prediction result.
- A pre-trained Random Forest model serialized using pickle.
- create_connection() : Establishes a connection to the database.
- create_table() : Creates tables in the database using schema.sql.
- insert_data() : Inserts user inputs and prediction result into the database.
- SQL script to create necessary tables for storing user inputs and prediction results.
- Form Fields : Dep_Time, Arrival_Time, stops, airline, Source, Destination
- User submits the form.
- Extracts form data using request.form.
- Processes date and time fields using pd.to_datetime.
- Encodes categorical variables (airline, source, destination).
- Extracts day, month, hour, minute from date and time fields.
- Encodes categorical features into binary format.
- Calculates flight duration in hours and minutes.
- Passes processed data to the Random Forest model.
- Receives the predicted fare.
- Stores the user inputs and prediction result in the database.
- Renders home.html with the prediction result.
-
Ensure all dependencies are installed. You can use the following command to install the required Python packages:
pip install -r requirements.txt
- Run your python file using :
python app.py
- Clone the repository:
git clone https://github.com/abuawaish/final_project_pw.git
- Open a web browser and go to http://192.168.206.14:5000 to access the application.
- Fill in the journey details in the form and submit to get the predicted flight fare.
- Add more features to improve prediction accuracy.
- Implement user authentication and save past searches.
- Enhance the UI for a better user experience.
- Expand the model to include more airlines and routes.
- This project is licensed under the MIT License.
-
The dataset used for training the model was obtained from
-
Inspiration for the project from various online tutorials and courses.
- Here is a screenshot of the application:
- Watch a demo of the application in action:
-
This project is deployed on Render.com. You can access the live model through the following link:
graph LR
A[User Interface] <---> B[Flask Backend] <---> C[Prediction Model]
B --> D[Data Processing]
B --> E[User Input]
C --> F[Database]
graph TD
A[home.html] --> B[Flask Application]
B --> C[Data Processing]
C --> D[Database]
B --> E[Prediction Model]
E --> F[flight_rf.pkl]
C --> H1[Input Parsing]
C --> H2[Feature Encoding]
D --> I1[database.py]
D --> I2[schema.sql]
E --> J1[Random Forest Model]
E --> J2[Serialized with pickle]
