Home > Blockchain >  XGB Regressor error - DataFrame for label cannot have multiple columns
XGB Regressor error - DataFrame for label cannot have multiple columns

Time:05-24

While using XGBRegressor() model for a housing price prediction, I have 13 features and target is price.

I have done the train test split but while fitting X_train data in model, I am getting below error.

ValueError: DataFrame for label cannot have multiple columns

All of the feature columns have only numerical data, so why getting this issue? Is it because of string data type of column name.

enter image description here

Please help!

CodePudding user response:

This is not about the features or column names. The error message is saying that when calling the fitting method, you passed a dataframe with more than one column as the y value. But y should be a one-dimensional vector, i.e. just one column. So make sure that you pass just the price column as y.

I'm assuming you are using the scikit-learn interface, where all the fitting methods for supervised learning methods expect X and y as input, X being the feature matrix and y the target or label vector.

CodePudding user response:

I had the same issue recently, I guess the package is corrupted. I completely uninstalled xgboost by pip uninstall. Then, installed it back again and restart from new kernel.

I assume you're running your code in jupyter notebook.

!pip uninstall xgboost

Then,

!pip install xgboost

This should solve the problem.

  • Related