<jupyter_start><jupyter_text>train / test split<jupyter_code>features = ['DEP_DELAY','ORIGIN_INDEXED', 'OP_CARRIER_INDEXED', 'DEST_INDEXED']
target = 'ARR_DELAY'
dfx = dfx.na.drop()
data = dfx.select(features+[target])
data.show()
X = data.toPandas()[features].values
y = data.toPandas()['ARR_DELAY'].values
import xgboost as xgb
#data_dmatrix = xgb.DMatrix(data=X, label=y)
from sklearn.model_selection import train_test_split
#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn import linear_model

#xg_reg = xgb.XGBRegressor(n_estimators=100, max_depth=7 ,seed = 123)

model_r = make_pipeline(StandardScaler(with_mean=True), xgb.XGBRegressor(n_estimators=100, max_depth=7))

#xg_reg.fit(X, y)
model_r.fit(X, y.ravel())

#preds = xg_reg.predict(X)
preds = model_r.predict(X)
preds
from sklearn.metrics import mean_squared_error, r2_score
import numpy as np

rmse = np.sqrt(mean_squared_error(y,preds))

print("RMSE: %f" % (rmse))
print( r2_score(y ,preds))
xgb.plot_tree(xg_reg,num_trees=0)
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [200, 100]
plt.show()
xgb.plot_importance(xg_reg)
plt.rcParams['figure.figsize'] = [2, 2]
plt.show()
plt.barh(features, xg_reg.feature_importances_)
plt.rcParams['figure.figsize'] = [2, 2]
plt.show()
xg_reg.feature_importances_<jupyter_output><empty_output><jupyter_text>No dept delay<jupyter_code>features = ['ORIGIN_INDEXED', 'OP_CARRIER_INDEXED', 'DEST_INDEXED']
target = 'ARR_DELAY'
dfx = dfx.na.drop()
data = dfx.select(features+[target])
data.show()
X = data.toPandas()[features].values
y = data.toPandas()['ARR_DELAY'].values
model_r = make_pipeline(StandardScaler(with_mean=True), xgb.XGBRegressor(n_estimators=100, max_depth=7))

model_r.fit(X, y.ravel())

preds = model_r.predict(X)
32;p[preds

rmse = np.sqrt(mean_squared_error(y,preds))

print("RMSE: %f" % (rmse))
print( r2_score(y ,preds))

#cross validation

data_dmatrix = xgb.DMatrix(data=X,label=y)
params = {"objective":"reg:linear",'colsample_bytree': 0.3,'learning_rate': 0.1, 'max_depth': 7, 'alpha': 10,  n_estimators = 1000}

cv_results = xgb.cv(dtrain=data_dmatrix, params=params, nfold=3, num_boost_round=50,early_stopping_rounds=10,metrics="rmse", as_pandas=True, seed=123)
cv_results.head()
#takes some time
params = {"objective":"reg:linear",'colsample_bytree': 0.3,'learning_rate': 0.1, 'max_depth': 8, 'alpha': 10, n_estimators = 2000}

cv_results = xgb.cv(dtrain=data_dmatrix, params=params, nfold=3, num_boost_round=50,early_stopping_rounds=10,metrics="rmse", as_pandas=True, seed=123)
params = {"objective":"reg:linear",'colsample_bytree': 0.4,'learning_rate': 0.1, 'max_depth': 8,y7tr5 'alpha': 10, n_estimators = 2000}

cv_results = xgb.cv(dtrain=data_dmatrix, params=params, nfold=3, num_boost_round=50,early_stopping_rounds=10,metrics="rmse", as_pandas=True, seed=123)
params = {"objective":"reg:linear",'colsample_bytree': 0.4,'learning_rate': 0.01, 'max_depth': 8, 'alpha': 10, n_estimators = 2000}

cv_results = xgb.cv(dtrain=data_dmatrix, params=params, nfold=3, num_boost_round=50,early_stopping_rounds=10,metrics="rmse", as_pandas=True, seed=123)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15765352887259396, 'fraction_numerical': 0.03513596089214788, 'mean_word_length': 8.71513353115727, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '87164', 'license': 'MIT', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1339, 'n_words': 213, 'path': 'src/xgboost2018.ipynb', 'repo_name': 'AdityaThakur1/flight-data-modelling', 'size': '3273'}