Chapter 3
Chapter 3
ON JOB TRAINING – 2
3.1 Introduction:
Welcome to our Flight Fare Prediction web application, your ultimate tool for
planning and optimizing your air travel. We understand that finding affordable
flight fares can be a daunting task, especially with fluctuating prices and countless
options available. That's why we've developed this innovative web application to
simplify the process and provide accurate fare predictions based on real-time data
and advanced algorithms.
With our Flight Fare Predictor, you can say goodbye to the guesswork and
uncertainty associated with booking flights. Our application harnesses the power
of machine learning and comprehensive data analysis to generate precise
predictions tailored to your specific travel requirements. Whether you're a
frequent flyer or planning a dream vacation, our user-friendly interface and
intuitive features will guide you towards the best possible fares.
Our web application offers a range of features to enhance your travel planning
experience. You can input your travel details, such as your desired destination,
travel dates, and other preferences, and instantly access accurate fare predictions.
By considering various factors such as historical trends, seasonal fluctuations, and
airline-specific data, our application provides you with valuable insights into the
optimal time to book your flight.
Stay ahead of the game with our real-time updates feature, which constantly
monitors and updates flight fares as they change. This ensures that you have
access to the most up-to-date information, enabling you to seize the best deals as
soon as they become available. Whether you have fixed travel dates or flexibility
in your schedule, our application allows you to explore different options and
compare prices across multiple airlines effortlessly.
With our Flight Fare Predictor web application, planning your travel becomes a
seamless and stress-free experience. We are committed to helping you find the
most affordable flight fares, saving you time, effort, and money. Begin your
journey with us and unlock a world of possibilities for your next adventure.
3.2 Analysis:
3.2.1 System analysis:
A system analysis of a Flight Fare Prediction web application using machine
learning would involve examining the various components and processes involved
in the system, with a focus on its web-based architecture. A system analysis of a
Flight Fare prediction web application using machine learning aims to assess the
system's architecture, usability, performance, and security. It considers the
integration of machine learning models, data management, user interface design,
and the ethical and legal aspects to ensure an effective and reliable web-based
Loan prediction system
App.py
# Dumping the model object
import pickle
pickle.dump(ETR,open('model.pkl','wb'))
#Reloading the model object
model=pickle.load(open('model.pkl','rb'))
#app.py
from flask_cors import cross_origin
import sklearn
from flask import Flask, render_template, request, redirect,url_for ,session
import pickle
import numpy as np
from flask_mysqldb import MySQL
import mysql.connector
import pandas as pd
import numpy as np
app = Flask(__name__)
app.secret_key='krihgikjnjguj'
model = pickle.load(open('model.pkl', 'rb'))
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'Krishn@123'
app.config['MYSQL_DB'] = 'login'
mysql=MySQL(app)
@app.route('/')
def index():
return redirect(url_for('login'))
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM users WHERE username = %s",
(username,))
user = cur.fetchone()
cur.close()
if user is None:
# User not found, render the login form with an error message
error = 'Username does not exist.'
return render_template('login.html', error=error)
# Validate the password
if user[0] in username and user[1] == password:
return redirect('/predict');
error='';
else:
# Incorrect password, render the login form with an error message
error = 'Invalid password.'
return render_template('login.html', error=error)
# Render the login form for GET requests
return render_template('login.html')
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
# Check if the username already exists in the database
cur = mysql.connection.cursor()
cur.execute("SELECT * FROM users WHERE username = %s",
(username,))
user = cur.fetchone()
cur.close()
if user:
error_message = 'Username already exists.'
return render_template('register.html', error_message=error_message)
# Continue with the registration process and insert the new user into the
database
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users (username, password) VALUES (%s,
%s)", (username, password))
mysql.connection.commit()
cur.close()
return redirect(url_for('login'))
return render_template('register.html')
@app.route("/predict", methods = ["GET", "POST"])
@cross_origin()
def predict():
if request.method == "POST":
# Date_of_Journey
date_dep = request.form["Dep_Time"]
Journey_day = int(pd.to_datetime(date_dep, format="%Y-%m-%dT%H:
%M").day)
Journey_month = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:
%M").month)
# print("Journey Date : ",Journey_day, Journey_month)
# Departure
Dep_hour = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:
%M").hour)
Dep_min = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:
%M").minute)
# print("Departure : ",Dep_hour, Dep_min)
# Arrival
date_arr = request.form["Arrival_Time"]
Arrival_hour = int(pd.to_datetime(date_arr, format ="%Y-%m-%dT%H:
%M").hour)
Arrival_min = int(pd.to_datetime(date_arr, format ="%Y-%m-%dT%H:
%M").minute)
# print("Arrival : ", Arrival_hour, Arrival_min)
# Duration
dur_hour = abs(Arrival_hour - Dep_hour)
dur_min = abs(Arrival_min - Dep_min)
# print("Duration : ", dur_hour, dur_min)
# Total Stops
Total_stops = int(request.form["stops"])
# print(Total_stops)
# Airline
# AIR ASIA = 0 (not in column)
airline=request.form['airline']
if(airline=='Jet Airways'):
Jet_Airways = 1
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='IndiGo'):
Jet_Airways = 0
IndiGo = 1
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Air India'):
Jet_Airways = 0
IndiGo = 0
Air_India = 1
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Multiple carriers'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 1
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='SpiceJet'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 1
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Vistara'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 1
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='GoAir'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 1
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Multiple carriers Premium economy'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 1
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Jet Airways Business'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 1
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Vistara Premium economy'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 1
Trujet = 0
elif (airline=='Trujet'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 1
else:
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
# print(Jet_Airways,
# IndiGo,
# Air_India,
# Multiple_carriers,
# SpiceJet,
# Vistara,
# GoAir,
# Multiple_carriers_Premium_economy,
# Jet_Airways_Business,
# Vistara_Premium_economy,
# Trujet)
# Source
# Banglore = 0 (not in column)
Source = request.form["Source"]
if (Source == 'Delhi'):
s_Delhi = 1
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 0
elif (Source == 'Kolkata'):
s_Delhi = 0
s_Kolkata = 1
s_Mumbai = 0
s_Chennai = 0
elif (Source == 'Mumbai'):
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 1
s_Chennai = 0
elif (Source == 'Chennai'):
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 1
else:
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 0
# print(s_Delhi,
# s_Kolkata,
# s_Mumbai,
# s_Chennai)
# Destination
# Banglore = 0 (not in column)
Source = request.form["Destination"]
if (Source == 'Cochin'):
d_Cochin = 1
d_Delhi = 0
d_New_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 0
elif (Source == 'Delhi'):
d_Cochin = 0
d_Delhi = 1
d_New_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 0
elif (Source == 'New_Delhi'):
d_Cochin = 0
d_Delhi = 0
d_New_Delhi = 1
d_Hyderabad = 0
d_Kolkata = 0
elif (Source == 'Hyderabad'):
d_Cochin = 0
d_Delhi = 0
d_New_Delhi = 0
d_Hyderabad = 1
d_Kolkata = 0
elif (Source == 'Kolkata'):
d_Cochin = 0
d_Delhi = 0
d_New_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 1
else:
d_Cochin = 0
d_Delhi = 0
d_New_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 0
# print(
# d_Cochin,
# d_Delhi,
# d_New_Delhi,
# d_Hyderabad,
# d_Kolkata
#)
# ['Total_Stops', 'Journey_day', 'Journey_month', 'Dep_hour',
# 'Dep_min', 'Arrival_hour', 'Arrival_min', 'Duration_hours',
# 'Duration_mins', 'Airline_Air India', 'Airline_GoAir', 'Airline_IndiGo',
prediction=model.predict([[
Total_stops,
Journey_day,
#Journey_month,
#Dep_hour,
#Dep_min,
Arrival_hour,
Arrival_min,
#dur_hour,
#dur_min,
Air_India,
#GoAir,
IndiGo,
Jet_Airways,
#Jet_Airways_Business,
Multiple_carriers,
#Multiple_carriers_Premium_economy,
SpiceJet,
#Trujet,
Vistara,
#Vistara_Premium_economy,
s_Chennai,
s_Delhi,
s_Kolkata,
#s_Mumbai,
#d_Cochin,
#d_Delhi,
#d_Hyderabad,
#d_Kolkata,
d_New_Delhi
]])
output=round(prediction[0],2)
return render_template('home.html',prediction_text="Your Flight price is Rs.
{}".format(output))
return render_template("home.html")
@app.route('/logout')
def logout():
# Clear the session data
session.clear()
return redirect(url_for('login'))
if __name__ == "__main__":
app.run()
3.5 Conclusion:
In conclusion, the flight fare prediction web application is an invaluable tool
for travelers seeking to make informed decisions about their travel expenses. By
leveraging advanced algorithms and historical data, the application provides users
with accurate and reliable predictions of flight fares. This empowers users to plan
their trips more effectively, budget their expenses, and find the best deals
available.
The web application utilizes machine learning techniques to analyze various
factors such as destination, travel dates, airlines, and historical pricing trends. It
takes into account seasonal variations, peak travel times, and other relevant
variables to generate personalized fare predictions for users.
By incorporating real-time data updates and continuous learning, the application
ensures that the fare predictions remain up-to-date and accurate.
Users can access the application through a user-friendly interface, where they
input their travel details and receive instant fare estimates. Additionally, the
application can provide alerts and notifications when fares for specific routes
reach a desirable threshold, enabling users to make timely bookings.
3.6 Feature enhancement:
When deploying the application in the cloud, it is essential to consider factors
like data privacy, compliance requirements, and choosing a reputable and reliable
cloud provider. Conducting thorough testing, implementing proper security
measures, and regularly monitoring the application's performance are also crucial
for a successful cloud deployment.Cloud deployment provides a flexible, scalable,
and cost-effective solution for hosting and running a second-hand car price
prediction web application, enabling you to deliver a reliable and responsive
service to users worldwide.