melik
melik

Reputation: 1332

Xgboost-ValueError: Please reshape the input data X into 2-dimensional matrix in python

I use XGBoost Algortihm for text mining but in below code I keep getting an error.

from xgboost import XGBClassifier
from numpy import *
xgb=XGBClassifier()
xgb.fit(df['doc_vector'],df.cat1)

How can I fix this? Thank you. enter image description here

Below types and print of the objects

enter image description here

Upvotes: 1

Views: 5810

Answers (1)

melik
melik

Reputation: 1332

Actually I got the solution from ValueError: matrix must be 2-dimensional when passing two arrays to the function Thanks.

xgb=XGBClassifier()
xgb.fit(np.vstack(df['doc_vector']),df.cat1)
predictions = xgb.predict(np.vstack(val['doc_vector']))

Upvotes: 4

Related Questions