'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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1