XGBoost example (Python)

# This script shows you how to make a submission using a few # useful Python libraries. # It gets a public leaderboard score of 0.76077. # Maybe you can tweak it and do better…? import pandas as pd import xgboost as xgb from sklearn.preprocessing import LabelEncoder import numpy as np # Load the data train_df = pd.read_csv(‘../input/train.csv’, header=0) test_df = pd.read_csv(‘../input/test.csv’, header=0) # We’ll impute missing values using the median for numeric columns and the most # common value for string columns. # This is based on some nice code by ‘sveitser’ at http://stackoverflow.com/a/25562948 from sklearn.base import TransformerMixin class DataFrameImputer(TransformerMixin): def fit(self, X, y=None): self.fill = pd.Series([X[c].value_counts().index[0] if X[c].dtype == np.dtype(‘O’) else X[c].median() for c in X], index=X.columns) return self def transform(self, X, y=None): return X.fillna(self.fill) feature_columns_to_use = [‘Pclass’,’Sex’,’Age’,’Fare’,’Parch’]…


Link to Full Article: XGBoost example (Python)

Pin It on Pinterest

Share This

Join Our Newsletter

Sign up to our mailing list to receive the latest news and updates about homeAI.info and the Informed.AI Network of AI related websites which includes Events.AI, Neurons.AI, Awards.AI, and Vocation.AI

You have Successfully Subscribed!