Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python XGBoost classifier can't `predict`: `TypeError: Not supported type for data`

I have a dataset like so:

print(X_test.dtypes)
metric1                    int64
rank                     float64
device_type                 int8
NA_estimate              float64

When I try to make predictions on this data set, I get the following error:

y_test_pred_xgb = clf_xgb.predict(xgb.DMatrix(X_test))
TypeError: Not supported type for data.<class 'xgboost.core.DMatrix'>

I searched for a bit but only found discussion of object variable data types causing issues. Is there something else wrong with my data or is the issue something else? I have looked at various blogs and Kaggle code without luck.

like image 613
user2205916 Avatar asked May 28 '26 23:05

user2205916


2 Answers

I faced the same problem and solved it by casting the data type using np.float32():

model.predict(np.float32(X_test))
like image 122
Azzam Radman Avatar answered May 31 '26 13:05

Azzam Radman


I had the same problem. Your clf_xgb model object is an implementation of Scikit-Learn API. DMatrix is an internal data structure that is used by XGBoost. Maybe this caused the problem.

You can try with:

clf_xgb.get_booster().predict(xgb.DMatrix(X_test))

In my case, this worked.

like image 44
CyberPlayerOne Avatar answered May 31 '26 13:05

CyberPlayerOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!