Error in Python script Expected 2D array got 1D array instead

0 votes

I wanted to make this ML prediction so I followed  this tutorial.

 ML Prediction:

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]
X.reshape(1, -1)

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

But I am getting this error:  "Expected 2D array, got 1D array instead:" and I am using python 3.6. What am I doing wrong here?

May 18, 2022 in Python by Kichu
• 19,050 points
1,218 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Python error "TypeError: range() integer end argument expected, got numpy.float64."

Hi @Kashish, try something like this: for i ...READ MORE

answered May 27, 2019 in Python by Harish
2,682 views
0 votes
1 answer

How do I trim the leading or trailing zeros from a 1d array in python?

Hey @Akki, you can use the numpy ...READ MORE

answered May 29, 2019 in Python by Wakir
1,462 views
0 votes
1 answer

How do I trim extra zeros from a 2D array in python?

Hey @Laksha, you can try something like ...READ MORE

answered May 29, 2019 in Python by Yamini
2,528 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
5,370 views
+4 votes
7 answers
+2 votes
4 answers

python 2d array

You should make a list of lists, ...READ MORE

answered Oct 18, 2018 in Python by ritu
992 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,090 points
1,456 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,090 points
715 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,090 points
1,850 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,090 points
699 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP