Skip to content
Advertisement

XGBoost Regressor cannot fit the model using string data

I’m trying to use XGBoost to predict a one target (one attribute) dataframe. Below my code. I run it on Colab

JavaScript

However, the following error is returned:

JavaScript

if I change the last line to

JavaScript

I get this error:

JavaScript

What I’m doing wrong? any clue?

Advertisement

Answer

XGBoost cannot handle categorical variables, so they need to be encoded before passing to XGBoost model. There are many ways you can encode your varaibles according to the nature of the categorical variable. Since I believe that your string have some order so Label Encoding is suited for your categorical variables:

Full code:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement