Kaggle competition: Predict Future Sales
my_submission.to_csv('submission.csv', index=False )<set_options>
def get_imports() :
for name, val in globals().items() :
if isinstance(val, types.ModuleType):
name = val.__name__.split(".")[0]
elif isinstance(val, type):
name = val.__module__.split(".")[0]
if name == "PIL":
name = "Pillow"
elif name == "sklearn":
name = "scikit-learn"
yield name
imports = list(set(get_imports()))
requirements = []
for m in pkg_resources.working_set:
if m.project_name in imports and m.project_name!="pip":
requirements.append(( m.project_name, m.version))
for r in requirements:
print("{}=={}".format(*r))
%matplotlib inline 
<load_from_csv>
data = pd.read_pickle('.. /input/eda-preprocessing-feature-engineering/all_data.pkl')
 data = data[data.date_block_num > 5]
test = pd.read_csv('.. /input/competitive-data-science-predict-future-sales/test.csv' ).set_index('ID')
 dropcols = [
"item_cnt_month_lag_12",
"item_cnt_month_lag_12_adv",
"date_item_target_enc_lag_12",
"date_shop_target_enc_lag_12",
"date_city_target_enc_lag_1",
"date_city_target_enc_lag_2",
"date_city_target_enc_lag_3",
"date_type_target_enc_lag_1",
"date_subtype_target_enc_lag_1",
"new_item_cat_avg_lag_1",
"new_item_cat_avg_lag_2",
"new_item_cat_avg_lag_3",
"new_item_shop_cat_avg_lag_1",
"new_item_shop_cat_avg_lag_2",
"new_item_shop_cat_avg_lag_3",
]
X_train = data[data.date_block_num < 33].drop(['item_cnt_month']+dropcols, axis=1)
 Y_train = data[data.date_block_num < 33]['item_cnt_month']
X_valid = data[data.date_block_num == 33].drop(['item_cnt_month']+dropcols, axis=1)
 Y_valid = data[data.date_block_num == 33]['item_cnt_month']
X_test = data[data.date_block_num == 34].drop(['item_cnt_month']+dropcols, axis=1)
 del data
gc.collect()
train = pd.read_csv('.. /input/digit-recognizer/train.csv')
 test = pd.read_csv('.. /input/digit-recognizer/test.csv' )<prepare_x_and_y>
start_time = time.time()
model = XGBRegressor(
 max_depth=10,
n_estimators=1500,
min_child_weight=0.5,
colsample_bytree=0.8,
subsample=0.7,
eta=0.01,
tree_method='gpu_hist',
seed=0)
 model.fit(
 X_train,
Y_train,
eval_metric="rmse",
eval_set=[(X_train, Y_train),(X_valid, Y_valid)],
verbose=True,
early_stopping_rounds = 100)
 print(f"training took {time.time() - start_time}s" )
Y_train=train['label']
X_train = train.drop(labels = ["label"],axis = 1)
 Y_train.value_counts()<feature_engineering>
start_time = time.time()
Y_test = model.predict(X_test ).clip(0, 20)
 print(f"predicting on test set took {time.time() - start_time}s")
 start_time = time.time()
Y_train_pred = model.predict(X_train ).clip(0, 20)
 print(f"Predicting on train set took {time.time() - start_time} s")
 start_time = time.time()
Y_valid_pred = model.predict(X_valid ).clip(0, 20)
 print(f"Predicting on valid set took {time.time() - start_time} s")
 submission = pd.DataFrame({
"ID": test.index,
"item_cnt_month": Y_test
})
 submission.to_csv('xgb_submission.csv', index=False)
 train_preds = pd.DataFrame({
"ID": X_train.index,
"item_cnt_month": Y_train_pred
})
 train_preds.to_csv('xgb_y_train.csv', index=False)
 valid_preds = pd.DataFrame({
"ID": X_valid.index,
"item_cnt_month": Y_valid_pred
})
 valid_preds.to_csv('xgb_y_valid.csv', index=False )
<categorify><EOS> 
dump(model, 'xgb_model.joblib' )