text_plain_output_1.png
from sklearn.metrics import mean_squared_error

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import OneHotEncoder,OrdinalEncoder

from xgboost import XGBRegressor

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

test = pd.read_csv('../input/30-days-of-ml/test.csv')
train = pd.read_csv('../input/30-days-of-ml/train.csv')
y = train.target
X = train.drop(['target'], axis=1)
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=0)

integer_features = list(X.columns[X.dtypes == 'int64'])
continuous_features = list(X.columns[X.dtypes == 'float64'])
categorical_features = list(X.columns[X.dtypes == 'object'])

OneEncoder = OneHotEncoder(handle_unknown='ignore', sparse=False)
OH_train_cols = pd.DataFrame(OneEncoder.fit_transform(X_train[categorical_features]))
OH_valid_cols = pd.DataFrame(OneEncoder.transform(X_valid[categorical_features]))
OH_train_cols.index = X_train.index
OH_valid_cols.index = X_valid.index
OH_numtrain_cols = X_train.drop(categorical_features, axis=1)
OH_numval_cols = X_valid.drop(categorical_features, axis=1)
OH_X_train = pd.concat([OH_train_cols, OH_numtrain_cols], axis=1)
OH_X_valid = pd.concat([OH_valid_cols, OH_numval_cols], axis=1)

model = XGBRegressor(n_estimators=700, random_state=0, learning_rate=0.05)
model.fit(OH_X_train, y_train)
predict = model.predict(OH_X_valid)
print(mean_squared_error(predict, y_valid, squared=False))