I got this error ‘DataFrame.dtypes for data must be int, float, bool or categorical’

We Are Going To Discuss About I got this error ‘DataFrame.dtypes for data must be int, float, bool or categorical’. So lets Start this Python Article.

I got this error ‘DataFrame.dtypes for data must be int, float, bool or categorical’

  1. How to solve I got this error 'DataFrame.dtypes for data must be int, float, bool or categorical'

    It seems that you have categorial data. Start_time and end_time are object type.
    You need either to drop them or to encode them.
    To drop them
    xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree', metric='multi:softmax') hr_pred = xgb_model.fit(x_train._get_numeric_data(), np.ravel(y_train, order='C')).predict(x_test._get_numeric_data()) print(classification_report(y_test, hr_pred))
    To encode them have a look at this library https://contrib.scikit-learn.org/category_encoders/

  2. I got this error 'DataFrame.dtypes for data must be int, float, bool or categorical'

    It seems that you have categorial data. Start_time and end_time are object type.
    You need either to drop them or to encode them.
    To drop them
    xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree', metric='multi:softmax') hr_pred = xgb_model.fit(x_train._get_numeric_data(), np.ravel(y_train, order='C')).predict(x_test._get_numeric_data()) print(classification_report(y_test, hr_pred))
    To encode them have a look at this library https://contrib.scikit-learn.org/category_encoders/

Solution 1

It seems that you have categorial data. Start_time and end_time are object type.

You need either to drop them or to encode them.

To drop them

xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree', 
                                  metric='multi:softmax')
hr_pred = xgb_model.fit(x_train._get_numeric_data(), np.ravel(y_train, order='C')).predict(x_test._get_numeric_data())
print(classification_report(y_test, hr_pred))

To encode them have a look at this library https://contrib.scikit-learn.org/category_encoders/

Original Author Carlos Mougan Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment