Gagan
Gagan

Reputation: 1923

xgboost TypeError: can not initialize DMatrix from DataFrame

I am getting the below error when creating a DMatrix from a data in python.

TypeError: can not initialize DMatrix from DataFrame
Exception AttributeError: "'DMatrix' object has no attribute 'handle'" in <bound method DMatrix.__del__ ofrix object at 0x584d210>> ignored

Upvotes: 6

Views: 14271

Answers (1)

Jeevan
Jeevan

Reputation: 8772

Without accompanying code my best guess is you are passing the pandas data-frame directly, instead you need to pass numpy representation of the dataframe ie., pandas.DataFrame.values as below

X_train = pd.read_csv("train.csv")
y_train = X_train['label']
X_train.drop(['label'],axis=1,inplace=True)
final_GBM.fit(X_train.values,y_train.values)

Upvotes: 1

Related Questions