Nicholas
Nicholas

Reputation: 167

Trouble in XGBoost changing DataFrame to DMatrix

I'm using XGBoost to do some calculations. After I read a csv file to test_data and pass it to xgb.DMatrix ,error shows.

    test_data.info()
    datas = xgb.DMatrix(test_data)

the output shows below:

RangeIndex: 5000 entries, 0 to 4999
Data columns (total 16 columns):
 #   Column            Non-Null Count  Dtype  
---  ------            --------------  -----  
 0   description       5000 non-null   Float64
 1   neighbourhood     5000 non-null   Float32
 2   latitude          5000 non-null   Float64
 3   longitude         5000 non-null   Float64
 4   type              5000 non-null   Float32
 5   accommodates      5000 non-null   Int64  
 6   bathrooms         5000 non-null   Float64
 7   bedrooms          5000 non-null   Int64  
 8   amenities         5000 non-null   Float32
 9   reviews           5000 non-null   Int64  
 10  review_rating     5000 non-null   Int64  
 11  review_scores_A   5000 non-null   Int64  
 12  review_scores_B   5000 non-null   Int64  
 13  review_scores_C   5000 non-null   Int64  
 14  review_scores_D   5000 non-null   Int64  
 15  instant_bookable  5000 non-null   Float32
dtypes: Float32(4), Float64(4), Int64(8)

ValueError: DataFrame.dtypes for data must be int, float or bool.

But it seems that all the type satisfy the required bool, float and int. Any help?

Upvotes: 0

Views: 2716

Answers (1)

Nicholas
Nicholas

Reputation: 167

test_data=np.array(test_data, dtype=float)

saved my life

I think the reason is that it doesn't like Float64, Float32 and Int64. So just change the type to float.

Upvotes: 1

Related Questions