Reputation: 49
I am trying to run a basic XGBoost model on python (v 3.8.5), however getting an error that I can not resolve. Appreciate your help, thanks!
My code is as below:
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import xgboost as xgb
# Read data and drop categorical variables; split as X and y
diamonds = sns.load_dataset("diamonds")
X, y = diamonds.drop(['price', 'color', 'cut', 'clarity'], axis = 1), diamonds[['price']]
# Split the data into train and test
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 1)
# Create regression matrices
dtrain_reg = xgb.DMatrix(X_train, y_train, enable_categorical = True)
dtest_reg = xgb.DMatrix(X_test, y_test, enable_categorical = True)
Getting an error at this stage:
ImportError Traceback (most recent call last)
<ipython-input-17-a1090b4630fd> in <module>
1 # Create regression matrices
----> 2 dtrain_reg = xgb.DMatrix(X_train, y_train, enable_categorical = True)
3 dtest_reg = xgb.DMatrix(X_test, y_test, enable_categorical = True)
....
....
~\Downloads\New folder\lib\site-packages\xgboost\data.py in pandas_transform_data(data)
474 """Handle categorical dtype and extension types from pandas."""
475 import pandas as pd
--> 476 from pandas import Float32Dtype, Float64Dtype
477
478 result: List[np.ndarray] = []
ImportError: cannot import name 'Float32Dtype' from 'pandas' (C:\Users\lordp\Downloads\New folder\lib\site-packages\pandas\__init__.py)
Upvotes: 0
Views: 61