'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 ?
Solution 1:[1]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
