Reputation: 43
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
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