text_html_output_1.png
from sklearn.metrics import mean_absolute_error

from sklearn.model_selection import train_test_split

from xgboost import XGBRegressor

import pandas as pd

train = pd.read_csv('/kaggle/input/tabular-playground-series-aug-2021/train.csv')
test = pd.read_csv('/kaggle/input/tabular-playground-series-aug-2021/test.csv')

train.shape

test.shape

train.pop('id')
test_ids = test.pop('id')

validation_split = 0.3
train_features, validation_features = train_test_split(train, test_size=validation_split)
train_targets, validation_targets = (train_features.pop('loss'), validation_features.pop('loss'))

model_1 = XGBRegressor(n_estimators=100, learning_rate=0.05)
model_2 = XGBRegressor(n_estimators=200, learning_rate=0.1)
model_3 = XGBRegressor(n_estimators=300, learning_rate=0.5)
model_4 = XGBRegressor(n_estimators=300, learning_rate=1, random_state=0)
models = [model_1, model_2, model_3, model_4]

def score_model(model):
    model.fit(train_features, train_targets, early_stopping_rounds=3, eval_set=[(validation_features, validation_targets)], verbose=False)
    preds = model.predict(validation_features)
    return mean_absolute_error(validation_targets, preds)
for i in range(0, len(models)):
    mae = score_model(models[i])
    print('Model %d MAE: %d' % (i + 1, mae))