<jupyter_start><jupyter_text>Using logistic regression to determine whether flights are delayed or non-delayed, where delayed will be at least 15min.<jupyter_code>pred = 'dep_delay'
features =  ['month','day','dep_time','arr_time','carrier','dest','air_time','distance', 
             'lat', 'lon', 'alt',  'dewp', 'humid', 'wind_speed', 'wind_gust', 
             'precip', 'pressure', 'visib' ]

features_v = df_overall[features]
pred_v = df_overall[pred]

pd.options.mode.chained_assignment = None
features_v['carrier'] = pd.factorize(features_v['carrier'])[0]
features_v['dest'] = pd.factorize(features_v['dest'])[0]

#setting delayed as 15min
how_late_is_late = 15.0

scaler = StandardScaler()
scaled_features_v = scaler.fit_transform(features_v)

features_train, features_test, pred_train, pred_test = train_test_split(
    scaled_features_v, pred_v, test_size=0.30, random_state=0)
clf_lr = sklearn.linear_model.LogisticRegression()                                                 
logistic_fit=clf_lr.fit(features_train, 
                        np.where(pred_train >= how_late_is_late,1,0))

predictions = clf_lr.predict(features_test)<jupyter_output><empty_output><jupyter_text>Report<jupyter_code>cm_lr = confusion_matrix(np.where(pred_test >= how_late_is_late,1,0), predictions)
print("Confusion matrix")
print(pd.DataFrame(cm_lr))

#Get accuracy
report_lr = precision_recall_fscore_support(
    list(np.where(pred_test >= how_late_is_late,1,0)), 
    list(predictions), average='binary')

#Print Accuracy
print ("\nprecision = %0.2f, recall = %0.2f, F1 = %0.2f, accuracy = %0.2f"
       % (report_lr[0], report_lr[1], report_lr[2],                                                                         
          accuracy_score(list(np.where(pred_test >= how_late_is_late,1,0)), list(predictions))))<jupyter_output>Confusion matrix
       0     1
0  48403  1243
1  12569  2171

precision = 0.64, recall = 0.15, F1 = 0.24, accuracy = 0.79
{'fraction_non_alphanumeric': 0.13165983606557377, 'fraction_numerical': 0.03483606557377049, 'mean_word_length': 3.8461538461538463, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '96044', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 712, 'n_tokens_neox': 671, 'n_words': 115, 'path': 'NYCflights13 - Scikit-learn Classification.ipynb', 'repo_name': 'kengying5/Data-Visualisation-with-Python', 'size': '1952'}