'After executing the last line i get following error: ValueError: y should be a 1d array, got an array of shape (4457, 2) instead
y = pd.get_dummies(messages['label'])
y = y.iloc[:,1].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20,random_state = 0)
from sklearn.naive_bayes import MultinomialNB
spam_detect_model = MultinomialNB().fit(X_train, y_train)
y_pred = spam_detect_model.predict(y_test)
<after this getting this error ValueError: y should be a 1d array, got an array of shape (4457, 2) instead.>
Solution 1:[1]
First of all, directly under your y
variable, do this to convert it to integer:
y = y.apply(lambda x: x.argmax(), axis=1).values
And y_pred = spam_detect_model.predict(X_test)
not y_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 | S.B |