Question: Python3 Here is a snippet of my Python code. Why am I getting a ValueError: Expected 2D array, got 1D array instead? from sklearn import

Python3

Here is a snippet of my Python code. Why am I getting a

ValueError: Expected 2D array, got 1D array instead? 

from sklearn import svm

X = [] Y = []

X = np.array(x3) Y = np.array(y3) validation_size = 0.20 seed = 7

X.reshape(-1, 1) Y.reshape(-1, 1)

X_train, X_validation, Y_train, Y_validation = model_selection.train_test_split(X, Y, test_size=validation_size, random_state=seed)

cmap_light = ListedColormap(['#AAAAFF', '#FFAAAA']) cmap_bold = ListedColormap(['#0000FF', '#FF0000'])

svm_clf= svm.SVC()

SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape='ovo', degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False)

svm_clf.fit(X_train,Y_train)

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!