How to do it...

We will now look at how to use a random forest to train our model:

  1. We start by splitting our target and feature variables:
predictor= df_creditcarddata.iloc[:, df_creditcarddata.columns != 'default.payment.next.month']target= df_creditcarddata.iloc[:, df_creditcarddata.columns == 'default.payment.next.month']
  1. We separate the numerical and non-numerical variables in our feature set:
# save all categorical columns in listcategorical_columns = [col for col in predictor.columns.values if predictor[col].dtype == 'object']# dataframe with categorical featuresdf_categorical = predictor[categorical_columns]# dataframe with numerical featuresdf_numeric = predictor.drop(categorical_columns, axis=1)
  1. We dummy code the categorical ...

Get Ensemble Machine Learning Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.