├── Procfile ├── flight_rf.pkl ├── static └── css │ └── styles.css ├── requirements.txt ├── README.md ├── templates └── home.html └── app.py /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /flight_rf.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Flight-Price-Prediction/HEAD/flight_rf.pkl -------------------------------------------------------------------------------- /static/css/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #e1f4f3; 3 | text-align: center; 4 | } 5 | 6 | .navbar { 7 | background-color: #333333; 8 | } 9 | 10 | a { 11 | color: #f1f9f9; 12 | } 13 | 14 | a:hover { 15 | color: #f0f0f0; 16 | } -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.3 2 | certifi==2020.6.20 3 | click==7.1.2 4 | distlib==0.3.0 5 | Flask==1.1.2 6 | Flask-Cors==3.0.8 7 | gunicorn==20.0.4 8 | itsdangerous==1.1.0 9 | Jinja2==2.11.2 10 | joblib==0.15.1 11 | MarkupSafe==1.1.1 12 | numpy==1.18.1 13 | pandas==1.0.1 14 | python-dateutil==2.8.1 15 | pytz==2019.3 16 | scikit-learn==0.22.1 17 | scipy==1.4.1 18 | six==1.14.0 19 | virtualenv==20.0.7 20 | Werkzeug==1.0.1 21 | wincertstore==0.2 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flight Fare Prediction: 2 | 3 | ## Table of Content 4 | * [Demo](#demo) 5 | * [Overview](#overview) 6 | * [Motivation](#motivation) 7 | * [Installation](#installation) 8 | * [Deployement on Heroku](#deployement-on-heroku) 9 | * [Directory Tree](#directory-tree) 10 | * [Bug / Feature Request](#bug---feature-request) 11 | * [Future scope of project](#future-scope) 12 | 13 | 14 | ## Demo 15 | Link: [https://flight-price-prediction-api.herokuapp.com/](https://flight-price-prediction-api.herokuapp.com/) 16 | 17 | [![](https://i.imgur.com/R1g2wvC.png)](https://flight-price-prediction-api.herokuapp.com/) 18 | 19 | [![](https://i.imgur.com/p0aeL6c.png)](https://flight-price-prediction-api.herokuapp.com/) 20 | 21 | ## Overview 22 | This is a Flask web app which predicts fare of Flight ticket. 23 | 24 | ## Motivation 25 | What to do when you are at home due to this pandemic situation? I started to learn Machine Learning model to get most out of it. I came to know mathematics behind all supervised models. Finally it is important to work on application (real world application) to actually make a difference. 26 | 27 | ## Installation 28 | The Code is written in Python 3.6.10. If you don't have Python installed you can find it [here](https://www.python.org/downloads/). If you are using a lower version of Python you can upgrade using the pip package, ensuring you have the latest version of pip. To install the required packages and libraries, run this command in the project directory after [cloning](https://www.howtogeek.com/451360/how-to-clone-a-github-repository/) the repository: 29 | ```bash 30 | pip install -r requirements.txt 31 | ``` 32 | 33 | ## Deployement on Heroku 34 | Login or signup in order to create virtual app. You can either connect your github profile or download ctl to manually deploy this project. 35 | 36 | [![](https://i.imgur.com/dKmlpqX.png)](https://heroku.com) 37 | 38 | Our next step would be to follow the instruction given on [Heroku Documentation](https://devcenter.heroku.com/articles/getting-started-with-python) to deploy a web app. 39 | 40 | ## Directory Tree 41 | ``` 42 | ├── static 43 | │   ├── css 44 | ├── template 45 | │   ├── home.html 46 | ├── Procfile 47 | ├── README.md 48 | ├── app.py 49 | ├── flight_price.ipynb 50 | ├── flight_rf.pkl 51 | ├── requirements.txt 52 | ``` 53 | 54 | ## Technologies Used 55 | 56 | ![](https://forthebadge.com/images/badges/made-with-python.svg) 57 | 58 | [](https://flask.palletsprojects.com/en/1.1.x/) [](https://gunicorn.org) [](https://scikit-learn.org/stable/) 59 | 60 | 61 | ## Bug / Feature Request 62 | 63 | If you find a bug (the website couldn't handle the query and / or gave undesired results), kindly open an [issue](https://github.com/Mandal-21/Flight-Price-Prediction/issues) here by including your search query and the expected result 64 | 65 | ## Future Scope 66 | 67 | * Use multiple Algorithms 68 | * Optimize Flask app.py 69 | * Front-End 70 | -------------------------------------------------------------------------------- /templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Flight Price Prediction 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 30 | 31 |


32 | 33 | 34 |
35 | 36 | 37 | 38 |
39 | 40 | 41 |
42 |
43 |
44 |
45 |
Departure Date
46 | 47 | 48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
Arrival Date
58 | 59 | 60 |
61 |
62 |
63 |
64 | 65 |
66 |
67 |
68 | 69 |
70 |
71 |
72 |
73 | 74 |
Source
75 | 81 |
82 |
83 |
84 |
85 |
86 |
87 |
Destination
88 | 89 | 96 |
97 |
98 |
99 |
100 | 101 | 102 | 103 |
104 |
105 |
106 | 107 |
108 |
109 |
110 |
111 |
Stopage
112 | 113 | 120 |
121 |
122 |
123 |
124 |
125 |
126 |
Which Airline you want to travel?
127 | 128 | 143 |
144 |
145 |
146 |
147 | 148 | 149 | 150 |
151 |
152 |
153 | 154 | 155 |
156 | 157 |
158 |
159 |

{{ prediction_text }}

160 | 161 |
162 |
163 |

©2020 Amar Mandal

164 | 165 |
166 | 167 | 168 | 169 | 170 | 171 | 174 | 177 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, render_template 2 | from flask_cors import cross_origin 3 | import sklearn 4 | import pickle 5 | import pandas as pd 6 | 7 | app = Flask(__name__) 8 | model = pickle.load(open("flight_rf.pkl", "rb")) 9 | 10 | 11 | 12 | @app.route("/") 13 | @cross_origin() 14 | def home(): 15 | return render_template("home.html") 16 | 17 | 18 | 19 | 20 | @app.route("/predict", methods = ["GET", "POST"]) 21 | @cross_origin() 22 | def predict(): 23 | if request.method == "POST": 24 | 25 | # Date_of_Journey 26 | date_dep = request.form["Dep_Time"] 27 | Journey_day = int(pd.to_datetime(date_dep, format="%Y-%m-%dT%H:%M").day) 28 | Journey_month = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:%M").month) 29 | # print("Journey Date : ",Journey_day, Journey_month) 30 | 31 | # Departure 32 | Dep_hour = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:%M").hour) 33 | Dep_min = int(pd.to_datetime(date_dep, format ="%Y-%m-%dT%H:%M").minute) 34 | # print("Departure : ",Dep_hour, Dep_min) 35 | 36 | # Arrival 37 | date_arr = request.form["Arrival_Time"] 38 | Arrival_hour = int(pd.to_datetime(date_arr, format ="%Y-%m-%dT%H:%M").hour) 39 | Arrival_min = int(pd.to_datetime(date_arr, format ="%Y-%m-%dT%H:%M").minute) 40 | # print("Arrival : ", Arrival_hour, Arrival_min) 41 | 42 | # Duration 43 | dur_hour = abs(Arrival_hour - Dep_hour) 44 | dur_min = abs(Arrival_min - Dep_min) 45 | # print("Duration : ", dur_hour, dur_min) 46 | 47 | # Total Stops 48 | Total_stops = int(request.form["stops"]) 49 | # print(Total_stops) 50 | 51 | # Airline 52 | # AIR ASIA = 0 (not in column) 53 | airline=request.form['airline'] 54 | if(airline=='Jet Airways'): 55 | Jet_Airways = 1 56 | IndiGo = 0 57 | Air_India = 0 58 | Multiple_carriers = 0 59 | SpiceJet = 0 60 | Vistara = 0 61 | GoAir = 0 62 | Multiple_carriers_Premium_economy = 0 63 | Jet_Airways_Business = 0 64 | Vistara_Premium_economy = 0 65 | Trujet = 0 66 | 67 | elif (airline=='IndiGo'): 68 | Jet_Airways = 0 69 | IndiGo = 1 70 | Air_India = 0 71 | Multiple_carriers = 0 72 | SpiceJet = 0 73 | Vistara = 0 74 | GoAir = 0 75 | Multiple_carriers_Premium_economy = 0 76 | Jet_Airways_Business = 0 77 | Vistara_Premium_economy = 0 78 | Trujet = 0 79 | 80 | elif (airline=='Air India'): 81 | Jet_Airways = 0 82 | IndiGo = 0 83 | Air_India = 1 84 | Multiple_carriers = 0 85 | SpiceJet = 0 86 | Vistara = 0 87 | GoAir = 0 88 | Multiple_carriers_Premium_economy = 0 89 | Jet_Airways_Business = 0 90 | Vistara_Premium_economy = 0 91 | Trujet = 0 92 | 93 | elif (airline=='Multiple carriers'): 94 | Jet_Airways = 0 95 | IndiGo = 0 96 | Air_India = 0 97 | Multiple_carriers = 1 98 | SpiceJet = 0 99 | Vistara = 0 100 | GoAir = 0 101 | Multiple_carriers_Premium_economy = 0 102 | Jet_Airways_Business = 0 103 | Vistara_Premium_economy = 0 104 | Trujet = 0 105 | 106 | elif (airline=='SpiceJet'): 107 | Jet_Airways = 0 108 | IndiGo = 0 109 | Air_India = 0 110 | Multiple_carriers = 0 111 | SpiceJet = 1 112 | Vistara = 0 113 | GoAir = 0 114 | Multiple_carriers_Premium_economy = 0 115 | Jet_Airways_Business = 0 116 | Vistara_Premium_economy = 0 117 | Trujet = 0 118 | 119 | elif (airline=='Vistara'): 120 | Jet_Airways = 0 121 | IndiGo = 0 122 | Air_India = 0 123 | Multiple_carriers = 0 124 | SpiceJet = 0 125 | Vistara = 1 126 | GoAir = 0 127 | Multiple_carriers_Premium_economy = 0 128 | Jet_Airways_Business = 0 129 | Vistara_Premium_economy = 0 130 | Trujet = 0 131 | 132 | elif (airline=='GoAir'): 133 | Jet_Airways = 0 134 | IndiGo = 0 135 | Air_India = 0 136 | Multiple_carriers = 0 137 | SpiceJet = 0 138 | Vistara = 0 139 | GoAir = 1 140 | Multiple_carriers_Premium_economy = 0 141 | Jet_Airways_Business = 0 142 | Vistara_Premium_economy = 0 143 | Trujet = 0 144 | 145 | elif (airline=='Multiple carriers Premium economy'): 146 | Jet_Airways = 0 147 | IndiGo = 0 148 | Air_India = 0 149 | Multiple_carriers = 0 150 | SpiceJet = 0 151 | Vistara = 0 152 | GoAir = 0 153 | Multiple_carriers_Premium_economy = 1 154 | Jet_Airways_Business = 0 155 | Vistara_Premium_economy = 0 156 | Trujet = 0 157 | 158 | elif (airline=='Jet Airways Business'): 159 | Jet_Airways = 0 160 | IndiGo = 0 161 | Air_India = 0 162 | Multiple_carriers = 0 163 | SpiceJet = 0 164 | Vistara = 0 165 | GoAir = 0 166 | Multiple_carriers_Premium_economy = 0 167 | Jet_Airways_Business = 1 168 | Vistara_Premium_economy = 0 169 | Trujet = 0 170 | 171 | elif (airline=='Vistara Premium economy'): 172 | Jet_Airways = 0 173 | IndiGo = 0 174 | Air_India = 0 175 | Multiple_carriers = 0 176 | SpiceJet = 0 177 | Vistara = 0 178 | GoAir = 0 179 | Multiple_carriers_Premium_economy = 0 180 | Jet_Airways_Business = 0 181 | Vistara_Premium_economy = 1 182 | Trujet = 0 183 | 184 | elif (airline=='Trujet'): 185 | Jet_Airways = 0 186 | IndiGo = 0 187 | Air_India = 0 188 | Multiple_carriers = 0 189 | SpiceJet = 0 190 | Vistara = 0 191 | GoAir = 0 192 | Multiple_carriers_Premium_economy = 0 193 | Jet_Airways_Business = 0 194 | Vistara_Premium_economy = 0 195 | Trujet = 1 196 | 197 | else: 198 | Jet_Airways = 0 199 | IndiGo = 0 200 | Air_India = 0 201 | Multiple_carriers = 0 202 | SpiceJet = 0 203 | Vistara = 0 204 | GoAir = 0 205 | Multiple_carriers_Premium_economy = 0 206 | Jet_Airways_Business = 0 207 | Vistara_Premium_economy = 0 208 | Trujet = 0 209 | 210 | # print(Jet_Airways, 211 | # IndiGo, 212 | # Air_India, 213 | # Multiple_carriers, 214 | # SpiceJet, 215 | # Vistara, 216 | # GoAir, 217 | # Multiple_carriers_Premium_economy, 218 | # Jet_Airways_Business, 219 | # Vistara_Premium_economy, 220 | # Trujet) 221 | 222 | # Source 223 | # Banglore = 0 (not in column) 224 | Source = request.form["Source"] 225 | if (Source == 'Delhi'): 226 | s_Delhi = 1 227 | s_Kolkata = 0 228 | s_Mumbai = 0 229 | s_Chennai = 0 230 | 231 | elif (Source == 'Kolkata'): 232 | s_Delhi = 0 233 | s_Kolkata = 1 234 | s_Mumbai = 0 235 | s_Chennai = 0 236 | 237 | elif (Source == 'Mumbai'): 238 | s_Delhi = 0 239 | s_Kolkata = 0 240 | s_Mumbai = 1 241 | s_Chennai = 0 242 | 243 | elif (Source == 'Chennai'): 244 | s_Delhi = 0 245 | s_Kolkata = 0 246 | s_Mumbai = 0 247 | s_Chennai = 1 248 | 249 | else: 250 | s_Delhi = 0 251 | s_Kolkata = 0 252 | s_Mumbai = 0 253 | s_Chennai = 0 254 | 255 | # print(s_Delhi, 256 | # s_Kolkata, 257 | # s_Mumbai, 258 | # s_Chennai) 259 | 260 | # Destination 261 | # Banglore = 0 (not in column) 262 | Source = request.form["Destination"] 263 | if (Source == 'Cochin'): 264 | d_Cochin = 1 265 | d_Delhi = 0 266 | d_New_Delhi = 0 267 | d_Hyderabad = 0 268 | d_Kolkata = 0 269 | 270 | elif (Source == 'Delhi'): 271 | d_Cochin = 0 272 | d_Delhi = 1 273 | d_New_Delhi = 0 274 | d_Hyderabad = 0 275 | d_Kolkata = 0 276 | 277 | elif (Source == 'New_Delhi'): 278 | d_Cochin = 0 279 | d_Delhi = 0 280 | d_New_Delhi = 1 281 | d_Hyderabad = 0 282 | d_Kolkata = 0 283 | 284 | elif (Source == 'Hyderabad'): 285 | d_Cochin = 0 286 | d_Delhi = 0 287 | d_New_Delhi = 0 288 | d_Hyderabad = 1 289 | d_Kolkata = 0 290 | 291 | elif (Source == 'Kolkata'): 292 | d_Cochin = 0 293 | d_Delhi = 0 294 | d_New_Delhi = 0 295 | d_Hyderabad = 0 296 | d_Kolkata = 1 297 | 298 | else: 299 | d_Cochin = 0 300 | d_Delhi = 0 301 | d_New_Delhi = 0 302 | d_Hyderabad = 0 303 | d_Kolkata = 0 304 | 305 | # print( 306 | # d_Cochin, 307 | # d_Delhi, 308 | # d_New_Delhi, 309 | # d_Hyderabad, 310 | # d_Kolkata 311 | # ) 312 | 313 | 314 | # ['Total_Stops', 'Journey_day', 'Journey_month', 'Dep_hour', 315 | # 'Dep_min', 'Arrival_hour', 'Arrival_min', 'Duration_hours', 316 | # 'Duration_mins', 'Airline_Air India', 'Airline_GoAir', 'Airline_IndiGo', 317 | # 'Airline_Jet Airways', 'Airline_Jet Airways Business', 318 | # 'Airline_Multiple carriers', 319 | # 'Airline_Multiple carriers Premium economy', 'Airline_SpiceJet', 320 | # 'Airline_Trujet', 'Airline_Vistara', 'Airline_Vistara Premium economy', 321 | # 'Source_Chennai', 'Source_Delhi', 'Source_Kolkata', 'Source_Mumbai', 322 | # 'Destination_Cochin', 'Destination_Delhi', 'Destination_Hyderabad', 323 | # 'Destination_Kolkata', 'Destination_New Delhi'] 324 | 325 | prediction=model.predict([[ 326 | Total_stops, 327 | Journey_day, 328 | Journey_month, 329 | Dep_hour, 330 | Dep_min, 331 | Arrival_hour, 332 | Arrival_min, 333 | dur_hour, 334 | dur_min, 335 | Air_India, 336 | GoAir, 337 | IndiGo, 338 | Jet_Airways, 339 | Jet_Airways_Business, 340 | Multiple_carriers, 341 | Multiple_carriers_Premium_economy, 342 | SpiceJet, 343 | Trujet, 344 | Vistara, 345 | Vistara_Premium_economy, 346 | s_Chennai, 347 | s_Delhi, 348 | s_Kolkata, 349 | s_Mumbai, 350 | d_Cochin, 351 | d_Delhi, 352 | d_Hyderabad, 353 | d_Kolkata, 354 | d_New_Delhi 355 | ]]) 356 | 357 | output=round(prediction[0],2) 358 | 359 | return render_template('home.html',prediction_text="Your Flight price is Rs. {}".format(output)) 360 | 361 | 362 | return render_template("home.html") 363 | 364 | 365 | 366 | 367 | if __name__ == "__main__": 368 | app.run(debug=True) 369 | --------------------------------------------------------------------------------