<jupyter_start><jupyter_text>**Departure Time** is a key factor that we are going to examine.We want to know which time is the best time for flight.<jupyter_code>## Categoriza as variáveis departure_delay e arrival_delay
flights$departure_delay <- ordered(cut(flights$departure_delay, c(60,75,125,240)),
                              labels = c("None", "Low", "High"))

flights$arrival_delay <- ordered(cut(flights$arrival_delay, c(60,75,125,240)),
                              labels = c("None", "Low", "High"))

## Categoriza a variável depart_time
flights$depart_time <- ordered(cut(as.integer(substr(flights$depart_time,1,2)), c(00,06,12,18,23)),
                              labels = c("Overnight", "Morning", "Afternoon", "Evening"))

head(flights)
# Sum the flights delayed during Overnight
query<-"select count(flight) from flights where depart_time='Overnight'"
print(query)
result<-sqldf(query)
result
# Sum the flights delayed during Overnight and departure_delay='None'
query<-"select count(flight) from flights where depart_time='Overnight' and departure_delay='None'"
print(query)
result_2<-sqldf(query)
result_2<jupyter_output><empty_output><jupyter_text>Confidence = 0,1918 ou 19,18%<jupyter_code># Sum the flights delayed during Morning
query<-"select count(flight) from flights where depart_time='Morning'"
result_3<-sqldf(query)
result_3
# Sum the flights delayed during Morning and departure_delay='None'
query<-"select count(flight) from flights where depart_time='Morning' and departure_delay='None'"
result_4<-sqldf(query)
result_4<jupyter_output><empty_output><jupyter_text>Confidence = 0,2363 ou 23,63%<jupyter_code># Sum the flights delayed during Afternoon
query<-"select count(flight) from flights where depart_time='Afternoon'"
result_5<-sqldf(query)
result_5
# Sum the flights delayed during Afternoon and departure_delay='None'
query<-"select count(flight) from flights where depart_time='Afternoon' and departure_delay='None'"
result_6<-sqldf(query)
result_6<jupyter_output><empty_output><jupyter_text>Confidence = 0,2531 ou 25,31%<jupyter_code># Sum the flights delayed during Evening
query<-"select count(flight) from flights where depart_time='Evening'"
result_7<-sqldf(query)
result_7
# Sum the flights delayed during Evening and departure_delay='None'
query<-"select count(flight) from flights where depart_time='Evening' and departure_delay='None'"
result_8<-sqldf(query)
result_8<jupyter_output><empty_output><jupyter_text>Confidence = 0,2749 ou 27,49% **Flights Departed Without Delay****Period of Time**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**(%)**Overnight&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;19,18%Morning&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;23,63%Afternoon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;25,31%Evening&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;27,49%**Conclusion:** The best time period to flight is from 19H to 23H (Evening) Creating the transactions and running the Apriori Algorithm,we have the same results.<jupyter_code>## Cria as transações
train_set_transactions <- as(flights, "transactions")
train_set_transactions
str(train_set_transactions)
head(train_set_transactions@data)
head(train_set_transactions@itemInfo)
head(train_set_transactions@itemsetInfo)
# Nesta parte do trabalho, executar-se-á o algoritmo APRIORI
# para gerar regras com a seguinte especificcação:
#
# 1. com suporte de 0,5, confiança de 0,9 e tamanho minimo = 2
# 2. com um atributo do lado esquerdo e um do lado direito e tamanho maximo=3
# 3. com lado direito limitado ao valor do atributo arrival_delay=None Arrival Delay
# 4. e lado esquerdo livre.
#
# Isso significa que estamos interessados em qualquer causa que provoque
# a consequência arrival_delay=High Arrival Delay. 
#rules <- apriori(train_set_transactions, parameter=list(supp = 0.01, conf = 0.8, minlen=1, maxlen= 10, target = "rules"), appearance=list(rhs = c("arrival_delay=High"),default="lhs"),control=NULL)
#rules <- apriori(train_set_transactions, parameter=list(conf = 0.9, minlen=1, maxlen= 10, target = "rules"), appearance=list(rhs = c("arrival_delay=None"),default="lhs"),control=NULL)
#rules <- apriori(train_set_transactions, parameter = list(supp = 0.9, conf = 0.9, target = "rules"), appearance=list(rhs = c("arrival_delay=High"),default="lhs"),control=NULL)
rules <- apriori(train_set_transactions, parameter = list(supp = 0.01, conf = 0.1, target = "rules"), appearance=list(lhs = c("depart_time=Evening"), rhs = c("departure_delay=None")),control=NULL)
rules_a <- as(rules, "data.frame")
head(rules_a)
irules <- inspect(rules)
rules.sorted <- sort(rules, by="lift")
inspect(rules.sorted)<jupyter_output>lhs                      rhs                    support    confidence
[1] {depart_time=Evening} => {departure_delay=None} 0.09090401 0.2749493 
[2] {}                    => {departure_delay=None} 0.24789126 0.2478913 
    lift     count
[1] 1.109153  4882
[2] 1.000000 13313
{'fraction_non_alphanumeric': 0.1416988416988417, 'fraction_numerical': 0.037644787644787646, 'mean_word_length': 6.744394618834081, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '491130', 'license': 'MIT', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1716, 'n_words': 391, 'path': 'CLAUDIO_TEIXEIRA_TRAB_DM_v3.ipynb', 'repo_name': 'jcolares/DM2018', 'size': '5180'}