Kaggle competition: Eval Lab 2 F464
ts = time.time()
model = XGBRegressor(
 max_depth=10,
n_estimators=1000,
min_child_weight=0.5,
colsample_bytree=0.8,
subsample=0.8,
eta=0.1,
seed=42)
 model.fit(
 X_train,
Y_train,
eval_metric="rmse",
eval_set=[(X_train, Y_train),(X_valid, Y_valid)],
verbose=True,
early_stopping_rounds = 20)
 time.time() - ts<save_to_csv>
%matplotlib inline
warnings.filterwarnings('ignore')
Y_pred = model.predict(X_valid ).clip(0, 20)
 Y_test = model.predict(X_test ).clip(0, 20)
 submission = pd.DataFrame({
"ID": test.index,
"item_cnt_month": Y_test
})
 submission.to_csv('xgb_submission.csv', index=False)
 pickle.dump(Y_pred, open('xgb_train.pickle', 'wb'))
pickle.dump(Y_test, open('xgb_test.pickle', 'wb'))<define_variables>
df = pd.read_csv('/kaggle/input/eval-lab-2-f464/train.csv')
 test = pd.read_csv('/kaggle/input/eval-lab-2-f464/test.csv' )
train_path = ".. /input/competitive-data-science-predict-future-sales/sales_train.csv"
test_path = ".. /input/competitive-data-science-predict-future-sales/test.csv"
items_path = ".. /input/competitive-data-science-predict-future-sales/items.csv"
shops_path = ".. /input/competitive-data-science-predict-future-sales/shops.csv"
item_cat_path = ".. /input/competitive-data-science-predict-future-sales/item_categories.csv"<load_from_csv>
num_features = ['id','chem_1', 'chem_2', 'chem_4','chem_5','chem_6','attribute']
num_features1 = ['chem_1', 'chem_2', 'chem_4','chem_5','chem_6','attribute']
X_train = df[num_features]
y_train = df["class"]
X = X_train
y = y_train
items = pd.read_csv(items_path)
 cats = pd.read_csv(item_cat_path)
 shops = pd.read_csv(shops_path)
 train = pd.read_csv(train_path)
 test = pd.read_csv(test_path)
<feature_engineering>
train = train[train.item_price > 0].reset_index(drop = True)
 train.loc[train.item_cnt_day < 1, "item_cnt_day"] = 0 
<feature_engineering>
clf1 = XGBClassifier().fit(X[num_features],y)
 y_pred1 = clf1.predict(test[num_features])
 clf2 = XGBClassifier().fit(X[num_features1],y)
 y_pred2 = clf2.predict(test[num_features1] )
<feature_engineering><EOS> 
answer = pd.DataFrame(data={'id':test['id'],'class':y_pred1})
 answer.to_csv('final1.csv',index=False)
 answer = pd.DataFrame(data={'id':test['id'],'class':y_pred2})
 answer.to_csv('final2.csv',index=False )