text_plain_output_1.png
from sklearn.compose import ColumnTransformer

from sklearn.metrics import mean_absolute_error

from sklearn.model_selection import train_test_split

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import OneHotEncoder

from xgboost import XGBRegressor

import pandas as pd

X_full = pd.read_csv('../input/30-days-of-ml/train.csv', index_col='id')
X_test_full = pd.read_csv('../input/30-days-of-ml/test.csv', index_col='id')
Sample_result = pd.read_csv('../input/30-days-of-ml/sample_submission.csv')

X_full.dropna(axis=0, subset=['target'], inplace=True)
y = X_full['target']
X_full.drop(['target'], axis=1, inplace=True)
X_train_full, X_valid_full, y_train, y_valid = train_test_split(X_full, y, train_size=0.8, test_size=0.2)

missing_values = X_train_full.isnull().sum()

cat_cols = [col for col in X_train_full.columns if X_train_full[col].dtype == 'object' and X_train_full[col].nunique() < 10]

cat_transformer = OneHotEncoder(handle_unknown='ignore')
preprocessor = ColumnTransformer(transformers=[('cat', cat_transformer, cat_cols)])

model = XGBRegressor()
clf = Pipeline(steps=[('preprocessor', preprocessor), ('model', model)])
clf.fit(X_full, y)
prediction = clf.predict(X_valid_full)
score = mean_absolute_error(prediction, y_valid)
print(f'Loss:{score}')