Kaggle competition: Tabular Playground Series - Jan 2021
<SOS> metric: RMSE Kaggle data source: tabular-playground-series-jan-2021<drop_column>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import KFold
from sklearn.metrics import mean_squared_error
import lightgbm as lgb
id_test = test2['id']
X_test = test2.drop(['id','relevance','product_title', 'search_term', 'product_description', 'search_term_tokens', 'product_title_tokens', 'product_description_tokens', 'product_info', 'attr', 'attribute', 'brand'], axis = 1 )<train_on_grid>
path = '.. /input/tabular-playground-series-jan-2021/'
seed = 42
splits = 5
model = LinearRegression().fit(X, y)
 y_pred = model.predict(X_test)
 print("RMSE using LinearRegressor:", caculator_RMSE(X, y, model))<train_model>
train = pd.read_csv(path + 'train.csv')
 test = pd.read_csv(path + 'test.csv')
 sample_submission = pd.read_csv(path + 'sample_submission.csv' )
regressor = RandomForestRegressor(n_estimators=20, random_state=0)
 regressor.fit(X, y)
 y_pred = regressor.predict(X_test)
 print("RMSE using RandomForest:", caculator_RMSE(X, y, regressor))<train_on_grid>
def model_lgb() :
return lgb.LGBMRegressor(boosting_type= 'gbdt',
num_leaves=31,
max_depth= 11,
learning_rate=0.1,
n_estimators=750,
subsample_for_bin=200000,
objective=None,
class_weight=None,
min_split_gain=0.0,
min_child_weight=0.001,
min_child_samples=20,
subsample=1.0,
subsample_freq=0,
colsample_bytree=1.0,
reg_alpha=0.0,
reg_lambda=0.0,
random_state=None,
n_jobs=- 1,
silent=True 
)
param_grid = {
'loss' : ['ls'],
'n_estimators' : [3],
'max_depth' : [9],
'max_features' : ['auto']
}
gbr = GradientBoostingRegressor()
model_gbr = sklearn.model_selection.GridSearchCV(estimator = gbr, n_jobs = -1, param_grid = param_grid)
 model_gbr.fit(X, y)
 y_pred = model_gbr.predict(X_test)
 print("RMSE using GBR:", caculator_RMSE(X, y, model_gbr))<train_on_grid>
mean_error = 0
all_predict = 0
cv = KFold(n_splits=splits, random_state=seed, shuffle=False)
 for train_index, test_index in cv.split(train):
x_train = train.loc[train_index, ::]
x_test = train.loc[test_index, ::]
y_train, y_test = x_train.target, x_test.target
x_train = x_train.drop(['id', 'target'], axis = 1)
 x_test = x_test.drop(['id', 'target'], axis = 1)
 model = model_lgb().fit(x_train, y_train)
 error = mean_squared_error(y_test, model.predict(x_test),squared=False)
 print(error, "
")
 mean_error += error
all_predict += model.predict(test.drop(['id'], axis=1))
print('mean error', mean_error/splits)
 predict = all_predict/splits
<set_options><EOS> 
sample_submission['target'] = predict
sample_submission.to_csv('submission.csv', index=False )