text_html_output_1.png
from sklearn.metrics import accuracy_score

from sklearn.preprocessing import OneHotEncoder

import pandas as pd

import xgboost as xgb

train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')

def encode(X_train, X_test, cat_cols):
    encoder = OneHotEncoder(categories='auto', sparse=False, handle_unknown='ignore')
    encoder.fit(X_train[cat_cols])
    X_train_encoded = encoder.transform(X_train[cat_cols])
    X_train_final = pd.concat([X_train.drop(cat_cols, axis=1), pd.DataFrame(X_train_encoded, index=X_train.index)], axis=1)
    X_test_encoded = encoder.transform(X_test[cat_cols])
    X_test_final = pd.concat([X_test.drop(cat_cols, axis=1), pd.DataFrame(X_test_encoded, index=X_test.index)], axis=1)
    return (X_train_final, X_test_final, encoder)

xgb_classifier = xgb.XGBClassifier()
xgb_classifier.fit(X_train_final, y_train)
y_pred = xgb_classifier.predict(X_test_final)
accuracy = accuracy_score(y_test, y_pred)
print('Accuracy:', accuracy)