Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Machine Learning by (19k points)

I'm following this tutorial to make this ML prediction:

import numpy as np

import matplotlib.pyplot as plt

from matplotlib import style


from sklearn import svm

x = [1, 5, 1.5, 8, 1, 9]

y = [2, 8, 1.8, 8, 0.6, 11]


X = np.array([[1,2],






y = [0,1,0,1,0,1]

X.reshape(1, -1)

clf = svm.SVC(kernel='linear', C = 1.0),y)


I'm using Python 3.6 and I get error "Expected 2D array, got 1D array instead:" I think the script is for older versions, but I don't know how to convert it to the 3.6 version.

Already try with the:

X.reshape(1, -1)

1 Answer

0 votes
by (33.1k points)

The array you passed in the predict() function, should be 2D array, but you passed 1-D array only.

For example:





And it should work

Hope this answer helps.

If you wish to Learn more about PythonVisit this Python Tutorial.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94k users

Browse Categories