You are just supposed to provide the predict method with the same 2D array, but with one value that you want to process (or more). In short, you can just replace
[0.58,0.76]
With
[[0.58,0.76]]
And it should work.
EDIT: This answer became popular so I thought I'd add a little more explanation about ML. The short version: we can only use predict on data that is of the same dimensionality as the training data (X) was.
In the example in question, we give the computer a bunch of rows in X (with 2 values each) and we show it the correct responses in y. When we want to predict using new values, our program expects the same - a bunch of rows. Even if we want to do it to just one row (with two values), that row has to be part of another array.
You are just supposed to provide the predict method with the same 2D array, but with one value that you want to process (or more). In short, you can just replace
[0.58,0.76]
With
[[0.58,0.76]]
And it should work.
EDIT: This answer became popular so I thought I'd add a little more explanation about ML. The short version: we can only use predict on data that is of the same dimensionality as the training data (X) was.
In the example in question, we give the computer a bunch of rows in X (with 2 values each) and we show it the correct responses in y. When we want to predict using new values, our program expects the same - a bunch of rows. Even if we want to do it to just one row (with two values), that row has to be part of another array.
The problem is occurring when you run prediction on the array [0.58,0.76]. Fix the problem by reshaping it before you call predict():
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm
x = [1, 5, 1.5, 8, 1, 9]
y = [2, 8, 1.8, 8, 0.6, 11]
plt.scatter(x,y)
plt.show()
X = np.array([[1,2],
[5,8],
[1.5,1.8],
[8,8],
[1,0.6],
[9,11]])
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear', C = 1.0)
clf.fit(X,y)
test = np.array([0.58, 0.76])
print test # Produces: [ 0.58 0.76]
print test.shape # Produces: (2,) meaning 2 rows, 1 col
test = test.reshape(1, -1)
print test # Produces: [[ 0.58 0.76]]
print test.shape # Produces (1, 2) meaning 1 row, 2 cols
print(clf.predict(test)) # Produces [0], as expected
ValueError: Expected 2D array, got 1D array instead - Example Notebook
machine learning - ValueError: y should be a 1d array, got an array of shape (1045, 5) instead - Data Science Stack Exchange
2D array value error
machine learning - Expected 2D array, got scalar array instead - Data Science Stack Exchange
Your data is multilabel: each row can have more than one label. But sklearn's Naive Bayes doesn't support that format of problem. You can use MultiOutputClassifier to wrap the Naive Bayes classifier, effectively training one model for each of the labels.
See the User Guide, especially the MultiOutput classification section. You may also want to consider the ClassifierChain (in the next section).
The last error you see is because you're using pandas structures, but reshape is a numpy method. Anyway, as @Oxbowerce observed, reshaping won't help; you need to deal with having multiple labels.
Your y values (i.e. the values that you want to predict) should be a 1d array, meaning that you are only trying to predict one type of value (instead of the 8 values you have in y_train). You should therefore select one of those columns as the column you want to predict with the Naive Bayes model.
The suggestion to reshape your array to 1d only really makes sense when you have 1 value you would like to predict but your array still has more than 1 dimension. The reason you are getting the error when reshaping is because .reshape is a numpy method that does not directly work on pandas.Series. Converting the pandas.Series to a numpy.array before using .reshape should work (but this doesn't make sense in your case as explained above, and will likely give other errors your y array is now longer than your X array).