1
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 ?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
DSP
  • 33
  • 1
  • 5

1 Answers1

2

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)
Community
  • 1
  • 1
yudhiesh
  • 6,383
  • 3
  • 16
  • 49