Kaggle competition: Tabular Playground Series - Jan 2021
y_train = train['relevance'].values
X_train = train.drop(['id', 'relevance'], axis = 1 ).values<drop_column>
PATH = '.. /input/tabular-playground-series-jan-2021/'
train = pd.read_csv(PATH + 'train.csv')
 test = pd.read_csv(PATH + 'test.csv')
 sample = pd.read_csv(PATH + 'sample_submission.csv')
 print(train.shape, test.shape )
id_test = test['id']
X_test = test.drop(['id', 'relevance'], axis = 1 ).values<train_on_grid>
FEATURES = train.drop(['id', 'target'], 1 ).columns
FEATURES
xgb = XGBRegressor()
param_grid = {'max_depth':[5, 6],
'n_estimators': [130, 150, 170],
'learning_rate' : [0.1]}
model_xgb = sklearn.model_selection.GridSearchCV(estimator = xgb, param_grid = param_grid, n_jobs = -1)
 model_xgb.fit(X_train, y_train)
 y_pred = model_xgb.predict(X_test )<feature_engineering>
cv = KFold(n_splits=5, shuffle=True)
 cv
for i in range(len(y_pred)) :
if y_pred[i] > 3:
y_pred[i] = 3<save_to_csv>
model = lgb.LGBMRegressor()
model
pd.DataFrame({"id": id_test, "relevance": y_pred} ).to_csv('submission.csv',index=False )<compute_train_metric>
X = train.drop(['id', 'target'], 1)
 y = train['target']
print(X.shape, y.shape )
def caculator_RMSE(X_train, y_train, model):
return np.sqrt(((y_train - model.predict(X_train)) ** 2 ).mean() )<compute_test_metric>
params = {
'n_estimators' : [100, 200, 500, 1000],
'learning_rate' : [0.01, 0.05, 0.1],
'subsample' : [1, 0.9, 0.8],
'feature_fraction' : [1, 0.9, 0.8]
}
clf = GridSearchCV(
 estimator=model,
cv=cv,
scoring='neg_root_mean_squared_error',
param_grid=params,
verbose=10
)
print('RMSE using XGBRegression : ' , caculator_RMSE(X_train, y_train, model_xgb))<split>
clf.fit(X, y)
 print(clf.best_score_)
 print(clf.best_estimator_ )
test1 = data_all_test[:74067]
test2 = data_all_test[74067:]<count_missing_values>
preds = clf.predict(test.drop(['id'], 1))
preds
test2.isnull().sum()<drop_column>
sample['target']= preds
sample
<prepare_x_and_y><EOS> 
sample.to_csv('submission.csv', index=False )