<jupyter_start><jupyter_text>THE NUMBER OF FLIGHTS WHICH GOT DIVERTED<jupyter_code>df['DIVERTED'].value_counts()
plt.figure(figsize=(16, 10))
hm=sns.heatmap(df.corr(),annot=True);
hm.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12);
df.drop(['YEAR','DAY_OF_WEEK','FLIGHT_NUMBER','AIRLINE','TAIL_NUMBER','TAXI_OUT','SCHEDULED_TIME','DEPARTURE_TIME','DISTANCE',
         'WHEELS_ON','TAXI_IN','WHEELS_OFF','SCHEDULED_TIME','ELAPSED_TIME','AIR_TIME','ARRIVAL_TIME','CANCELLATION_REASON'],
        axis=1,inplace=True)
df<jupyter_output>/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py:4174: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  errors=errors,<jupyter_text>FINDING AND REPLACING NAN VALUES WITH MEAN<jupyter_code>df.isna().sum()
from sklearn.impute import SimpleImputer 
imputer=SimpleImputer(missing_values=np.nan,strategy='mean')
imputer=imputer.fit(df.iloc[:,4:])
df.iloc[:,4:]=imputer.transform(df.iloc[:,4:])
df.head(10)<jupyter_output><empty_output><jupyter_text>Creating a dependent result variable<jupyter_code>df['RESULT']=df.apply(lambda df : 1 if df['ARRIVAL_DELAY']>15 else 0,axis=1)
df.head(10)
df['RESULT'].value_counts()
df.drop(['ORIGIN_AIRPORT','DESTINATION_AIRPORT'],axis=1,inplace=True)
df
from sklearn.preprocessing import StandardScaler
x=df.iloc[:,0:13]
y=df['RESULT']
scaler = StandardScaler()
scaler.fit(x)
scaler.transform(x)
x_train1, x_test1, y_train1,y_test1=train_test_split(x,y,test_size=0.30,random_state=42)
ans4 = DecisionTreeClassifier(random_state=0, max_depth=2)
ans4.fit(x_train1, y_train1)
y_pre4= ans4.predict(x_test1)
print("decision tree accuracy % :",accuracy_score(y_test1,y_pre4)*100)
print("decision tree roc_auc_score :",roc_auc_score(y_test1,y_pre4))
print("THE FIRST TEN PREDICTIONS ARE : ",end=" ")
df_3 = pd.DataFrame()
df_3['ACTUAL'] = y_test1
df_3['PREDICTED'] = y_pre4
df_3.head(10)
ax1 = sns.distplot(y_test1, hist=False, color="coral", label="Actual Value of Pred")
sns.distplot(y_pre4, hist=False, color="black", label="Fitted Values of Pred" , ax=ax1)
print("Report : ", classification_report(y_test1, y_pre4))
from sklearn.model_selection import GridSearchCV
params = {'max_leaf_nodes': list(range(2, 100)), 'min_samples_split': [2, 3, 4]}
grid_search_cv = GridSearchCV(DecisionTreeClassifier(random_state=42), params, verbose=1, cv=3)
grid_search_cv.fit(x_train1, y_train1)<jupyter_output>Fitting 3 folds for each of 294 candidates, totalling 882 fits
{'fraction_non_alphanumeric': 0.15306506205340353, 'fraction_numerical': 0.03384731101918014, 'mean_word_length': 8.366197183098592, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '525058', 'license': 'MIT', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1074, 'n_words': 160, 'path': 'Flight Delay Prediction/Flight_Delay_Prediction.ipynb', 'repo_name': '07yuvraj/datascience-mashup', 'size': '2659'}