ValueError in SKlearn from dimensions

Viewed 17

I have a DataFrame (as shown below) that is already set up with one-hot encoding. When I try to pass it into sklearn models, I keep getting dimension errors. If MultinomialNB only accept 1d arrays, how do I implement one-hot encoding?

Color Col B Col C Col D Col E
red 1 0 0 0
green 0 0 1 0
blue 0 1 0 0
green 0 0 1 0
brown 0 0 0 1

This runs fine:

cv = CountVectorizer(max_features = 1500)
X = cv.fit_transform(df['Color']).toarray()
y = df.loc[:, df.columns != 'Color'].values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0)

I get an error stating "ValueError: y should be a 1d array" when I run the following:

classifier = MultinomialNB()
classifier.fit(X_train, y_train)
0 Answers
Related