Professional Documents
Culture Documents
Abstract—Flight delay is an unexpected incident in the is streamed via Kafka to a trained machine learning
field of aviation in particular and transportation in general. model integrated in Spark, which is a powerful big data
Predicting the possibility or delay of flights plays a vital framework capable of processing huge amount of data
role in proactively arranging a time for the airline as well as
increasing the reputation of the airline among users. This and produce results in real-time. The real-time prediction
study presents an implementation of a real-time flight delay results are displayed through dashboard and stored in
prediction system. To ensure the practicality, the entire Cassandra database.
system is built using big data technology. Apache Kafka is The structure of the paper is as follow. The process
used to stream the flight data to trained machine learning
models integrated inside Apache Spark to output real-time
of constructing flight dataset and dataset analysis are
prediction results, which will be displayed through a dash- presented in Section III. The approach for building the
board and stored in Cassandra database simultaneously. real-time flight delay prediction system is described in
Consequently, the system can process a huge amount of detail in Section IV. In Section V, We proceed to build
input data and produce prediction results in real-time. an experimental pipeline of Machine Learning models on
Index Terms—Flight Delay Prediction, Machine Learn-
ing, Spark, Kafka, Streaming, Cassandra.
the dataset and analyze the results to find the best model
and its limitations. Next, we proceed to build a timed
I. I NTRODUCTION flight delay backup simulation system implemented in
Section VI. Finally, we draw conclusions in Section VII.
One of the worst experiences of flying is delays or
even cancellations. To be fair, about 80% of flights are
on time - that is, within 15 minutes of the scheduled II. R ELATED WORKS
time. The remaining 20% is often delayed. Indeed, the
delay makes any of us frustrated because we must wait [9] This paper provides valuable research in the
a long time and miss many planned plans. There are field of flight delay analysis in places like US, Asia,
many reasons why a flight departs late compared to the Brazil, Europe. The analysis on many aspects of data
originally scheduled time, such as late arrival, weather such as planning (filght plan, Airline schedule, Airport
problems, security issues, technical problems, etc.,. The Schedule), temporal (Season, month, day of week, time
delay also takes a toll on airlines’ business strategies as of day), weather (Visibility, Ceiling, Convective weather,
they rely on customer trust and return to support their Surface weather), spatial (Airport, City, Region), opera-
loyal customers, and users will be affected by its reliable tions (Capacity, Demand), features (Airline Status, Air-
performance to users. port infrastructure, Aircraft model, Aircraft occupancy,
Flight delay prediction is a problem based on ana- Fares, Frequency), state of the system (Prior delay levels,
lyzing information provided before departure to extract Operational conditions) makes the data more grounded
useful information and then using mathematical models and the indications of the problem gradually reveal.
to predict flight delays. The problem is researched to Plus analysis of different methodologies such as machine
help airlines predict the possibility and delay of a flight learning, Operational Research, Network Representation,
to be ready to handle special situations, which is to notify Probabilistic Models, Statistical Analysis. The difficulty
customers so that they can be flexible in their own time, that the author mentions is that the data is getting bigger
helping to increase the user experience and compete with and bigger, and the challenge for data scientists to study
other airlines. airlines and airports will require a combination of in-
This study focusses on building a practical flight delay domain knowledge and scientific skills data learning to
prediction system. The practicality requires the system explore the trove of flight big data.
to be capable of processing large amount of data and With the knowledge of Bigdata, we will build a real-
produce the prediction results in real-time. To this end, time simulation system for flight delay prediction so that
the entire real-time flight delay prediction system in this more research can be done to help deploy other Bigdata
study is built using big data technology. The flight data systems into real applications economy is more specific.
III. F LIGHT DATASET C ONSTRUCTION AND
A NALYSIS
A. Flight Dataset
The dataset used in the flight delay prediction prob-
lem is collected from website Bureau of Transportation
Statistics (BTS). BTS is a part of Department of Trans-
portation (DOT) is the preeminent source of statistics on
commercial aviation, intermodal freight operations, and
transport economics, and provides context for planners
and the public to understand traffic statistics carriage.
BTS provides data information of flights from 1987 to
present. Flight information data is provided on a monthly
basis with an average of nearly half a million flight
information a month. Because the amount of data is
quite large and hardware is limited, we only use a few
months representing the quarters of the year to generate Fig. 1. Data model of the flight delay prediction
the model training dataset. We use flight information
data of 6/9/12–2021, 3/2022 for model training and flight TABLE I
D ETAILS OF PROPERTIES
information data April 2022 to stream emulated real-time
for the system. Index Feature Meaning
0 ID ID of flight.
We have collected the data of the above 4 months
1 QUARTER Quarter of the year (1-4).
and obtained a dataset containing 2,200,913 flight infor- 2 MONTH Month of the year (1-12).
mation data and many flights have missing values. Since 3 DAY OF MONTH Day in month (1-31).
the dataset has missing values, we perform preprocessing 4 DAY OF WEEK Day in week (1-7).
5 OP UNIQUE CARRIER Service carrier code.
steps to handle missing values. For flights with missing 6 ORIGIN Departure Airport.
values, we will remove that flight’s information. Feature 7 DEST Destination Airport.
DEP DELAY used by us as the output for the problem, 8 DISTANCE Distance between airports (mile).
it contains continuous values that are the difference in 9 CRS DEP TIME Estimated departure time.
Output, includes 3 labels:
minutes between the expected and actual departure times – 0: Not delay.
of the flights. To match the original goal and simplify 10 LABEL – 1: 30 or less minutes late.
the problem, we normalize feature DEP DELAY into 3 – 2: 30 or more minutes late or
cancel the flight.
labels as follows: for flights with actual early departure
time or on time will be labeled “0”, flights with actual
departure time less than 30 minutes late will be labeled - 2 respectively 61.5% – 25.6% – 12.9%. Our datasets
“1”, remaining flights with actual departure time more tend to have data imbalances when the number of labels
than 30 minutes late or subject to cancellation will 0 occupies 61.5% of the dataset, 2.4 times more than
be labeled “2”. Feature DEP DELAY is also renamed label 1 (25.6%) and 4.8 times more than label 2 (12.9%).
LABEL to fit the data and problem. After the process- This is also a challenge of our dataset.
ing is done, we get the dataset Flight Delays Dataset
contains 2,157,737 data lines and 11 attributes are flight IV. R EAL - TIME FLIGHT DELAY PREDICTION SYSTEM
information. Similarly, we create a dataset to stream the From the Flight Delays Dataset we created in Section
real-time emulator for the system containing 542,117 III, we perform data normalization steps before encod-
data lines and 11 feature. ing data as String Indexer, One Hot Encoding, Vector
We use the properties that favor the planning and Assembler, Data Standardization (are covered in more
temporal branches as shown in Fig. 1, with the desire detail in Part IV-A). To create a flight delay prediction
to use an optimal data set to bring out the full potential model, we proceed to build models Machine Learning as
of the whole system. Logistic Regression, Decision Tree Classifier, Random
Details of the attributes of the dataset are shown in Forest Classifier, Naive Bayes supported by Machine
Table I. Learning Library (MLlib) is a machine learning library
of Spark. To evaluate the model, we use 4 degrees of
B. Dataset Analysis measurement: Precision, Recall, Accuracy and F1–score
Fig. 2 shows the distribution and proportions of the (Part details IV-C).From the model evaluation, we will
three labels in the train/test set of our Flight Delays select the best and most viable model to proceed with
Dataset. We can see that the distribution of labels on building our flight delay prediction real–time simulation
train and test sets is similar with the label ratios 0 - 1 system.
xi − µk
zi = (1)
σk
Where µk and σk are the mean and standard deviation
of each k .th attribute, respectively. This standardization
converts the mean of the data set to 0 and its standard
deviation to 1.
P (x|y)P (y) P ×R
P (y|x) = (4) F − score : Fβ = (1 + β 2 ) × (9)
P (x) β2 × P + R
Suppose we split an event x into n different compo- For β = 1, the standard F–score is obtained, see
nents x1 , x2 , . . . , xn . Naive Bayes, as the name suggests, Equation 9.
relies on the naive assumption that x1 , x2 , . . . , xn are
P ×R
independent components. From there we can calculate F − score : F1 = F = 2 × (10)
as in (5): P +R
3) Accuracy: Another metric defined as the propor-
P (x|y) = P (x1 |y)P (x2 |y) . . . P (xn |y) (5) tion of true cases retrieved, both positive and negative,
out of all retrieved cases. Accuracy is a weighted aver-
Hence we have (6): age of inverse precision and precision. The higher the
n
Y Accuracy, the more efficient the model. However, this is
P (x|y) ∝ P (y) P (xi |y) (6) not true for problems with unbalanced datasets, see (11)
i=1 [2].
In practice, it is rare to find data whose components
TP + TN
are completely independent of each other. However, this Accuracy : A = (11)
assumption makes the calculation simple, the training TP + TN + FP + FN
data fast, and brings unexpected results with certain D. BigData Frameworks
classes of problems. Nowadays more and more data is generated by in-
C. Evaluation Metrics direct or direct ways. Along with the development of
technology devices, we can increasingly collect data in
many different ways, typically from social networks, IoT
TABLE II
C ONFUSION MATRIX devices in daily life silently collecting data. ours makes
the data more and more bloated. Big data now has a lot
Predicted annotation
Positive Negative
of different applications, from banking and securities to
Positive True Positive False Negative media or education, but how to use big data is an issue
Gold annotation
Negative False Positive True Negative that traditional tools and techniques cannot can handle.
This is why some frameworks are born to work with big
data. One of the powerful frameworks is Apache Spark = 38.50) and the RF model which was the worst model
which we use for this problem: flight delay prediction. (F1-macro test = 27.14% and could not predict the labels
Apache Spark is a large-scale open source data pro- “2”).
cessing framework which has huge computing power and Detailed results on each label of the DT model without
is easy to handle big data. Spark also provides many data normalization (best model) are shown in Table IV.
easy-to-use APIs to reduce the burden on developers in The results are descending in order of label “0”, label
distributed computing or big data processing. “1”, label “2”. Only one label has a high F1-score above
70% (label “0” – 78.60%), and the other two labels
V. E XPERIMENTS AND R ESULTS
have a relatively low F1-score (label “1” – 30.22% and
We build an experimental pipeline of Machine Learn- the label “2” – 26.99%). This result explains the data
ing (ML) models: Logistic Regression (LR), Decision imbalance when the number of labels “0” accounts for
Tree (DT), Random Forest (RF), Naive Bayes (NB) 61.5% (labels “2” accounts for only 12.9% in the Flight
using Spark ML Framework (Fig. 3). Delays Dataset, detailed in Fig. 2).
VI. S YSTEM A RCHITECTURE
The system architecture is divided into three main
phases, shown in Fig. 4. Phase 1 (blue) synthesizes,
processes data and builds machine learning models for
the system, phase 2 (red) streams data to predict flight
Fig. 3. Spark ML pipeline. delays, phase 3 (green) outputs results to the screen and
model update.
To avoid the randomness of the experimental results,
we performed 5 times of training and recorded the A. Model Selection Building Phase
results, then averaged the results. Table III presents the In fact, data is aggregated in many places and for
performance comparison results of ML datasets on train- Bigdata, the data is more distributed, so the application
ing and testing sets when the data normalization method of Bigdata processing tools like Kafka to create a data
is not used and the z-score normalization method is used. stream for the system to operate stably and efficiently
Because the dataset tends to have data imbalance, to high.
compare the performance of the models we rely on the In the initial phase, the aim is to use machine learning
F1-macro measure to evaluate. The LR model gives the methods supported by spark to create the best model for
same results when data normalization is not applied and this system. Through steps such as processing data IV-A,
data normalization is applied using z-score, the results encoding columns and then conducting training using
on the training and testing sets are quite similar (F1- many different methods.
macro train = 36.23% and F1-macro test = 36.25%). Training data compiled from many different sources
DT model when not applying data normalization gives will be sent by Kafka Producer to Kafka topic. Consumer
higher results when applying data normalization using then takes on the role of data transfer and transfers data
z-score (higher than 1.7% in training set and 0.69% directly to the Cassandra database for storage. Next, the
in testing set), The difference between training and data is loaded from Cassandra to train the models and
testing sets is quite large, from 2.67% – 3.77%. RF choose the best model to use as the main model of this
model when not applying data normalization gives lower system. Fig. 5 fully shows the data in small steps. The
results when applying data normalization by z-score steps of data processing, model training experiments in
(lower than 1.52% in training set and 1.54% in testing Section V show that the Decision Tree model has the
set), the result difference between training and testing best results, so we will use the Decision Tree model for
set is not significant, from 0.01% – 0.03%. Although this system.
the RF model is trained on all three labels “0”, “1” 1) Apache Kafka [5]: Kafka can be understood
and “2”, the model cannot predict the label “2” of the simply as a tool for streaming distributed data (data
dataset, i.e. is the prediction result of the model labeled from many different sources). Specifically, Kafka is an
only “0” and “1” in both training and testing sets. The open source, fully packaged, fault tolerant and instant
NB model gives superior results when applying the z- messaging system. It is because of its reliability that
score data normalization method (higher than 13.92% Kafka is gradually being replaced by the traditional
in the training set and 13.64% in the testing set), the messaging system. It is used for common messaging
result difference between training and testing set is not systems in different contexts. This is a consequence
significant, from 0.03% – 0.25%. In summary, the DT when horizontal scalability and reliable data transfer are
model does not apply data normalization for the best the most important requirements. Some Kafka use cases:
results (F1-macro test = 45.27%), followed by the NB Stream Processing, Log Aggregation, Website Activity
model with z-score normalization applied (F1-macro test Monitoring, Metrics Collection.
TABLE III
AVERAGE RESULTS OVER 5 TRAINING
TABLE IV
T HE RESULTS PER CLASS OF THE BEST MODEL ON TEST SET