DSP
DSP

Reputation: 43

How can I resolve this Error - " ValueError: Negative values in data passed to MultinomialNB (input X)

model_3 = MultinomialNB()
model_3.fit(X_train,np.ravel(y_train))
y_predict = model_3.predict(X_test)
accuracy = metrics.accuracy_score(y_test,y_predict)
print(accuracy)

I am getting an error:

ValueError: Negative values in data passed to MultinomialNB (input X)

How can I resolve this error ?

Upvotes: 2

Views: 11374

Answers (1)

yudhiesh
yudhiesh

Reputation: 6799

Try using MinMaxScaler() to preprocess the data before sending the data to the model. This normalizes it to the range 0 to 1 thus removing the negative numbers.

from sklearn.preprocessing import MinMaxScaler #fixed import

scaler = MinMaxScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

Upvotes: 4

Related Questions