text_plain_output_1.png
from sklearn.metrics import mean_squared_error, mean_absolute_error

from sklearn.preprocessing import LabelEncoder

from xgboost import XGBRegressor

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train = pd.read_csv('../input/30-days-of-ml/train.csv')
test = pd.read_csv('../input/30-days-of-ml/test.csv')

categorical = [col for col in train.columns if train[col].dtype == 'object']
encoder = LabelEncoder()
for column in categorical:
    train[column] = encoder.fit_transform(train[column])
    test[column] = encoder.transform(test[column])

X = train.drop(['id', 'target'], axis=1)
y = train['target']
X_valid = test.drop(['id'], axis=1)

model = XGBRegressor(n_estimators=1000, learning_rate=0.05, gamma=0.2)
model.fit(X_train, y_train, early_stopping_rounds=5, eval_set=[(X_test, y_test)], verbose=False)
y_predict = model.predict(X_test)

predictions = model.predict(X_valid)
sample_sub = pd.read_csv('../input/30-days-of-ml/sample_submission.csv')
submission = pd.DataFrame({'Id': sample_sub['id'], 'target': predictions.astype(float)})
submission.to_csv('./my_submission.csv', index=False)
print('Your submission was successfully saved!')