Python Forum
error in script "Expected 2D array, got 1D array instead:"
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error in script "Expected 2D array, got 1D array instead:"
#1
Im following this tutorial to make this ML prediction:

http s://pythonprogramming .net/linear-svc-example-scikit-learn-svm-python

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)

print(clf.predict([0.58,0.76]))
Im using Kaggle with Pyhton 3.6 and i get "Expected 2D array, got 1D array instead:"

Already try with the:

X.reshape(1, -1)
but keep saying the same thing.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 303 Mar-26-2024, 02:18 PM
Last Post: snippsat
  boolean array: looking for all rows where all is True paul18fr 4 1,175 Jan-04-2023, 09:58 PM
Last Post: paul18fr
  reshaping 2D numpy array paul18fr 3 971 Jan-03-2023, 06:45 PM
Last Post: paul18fr
  Turn list of arrays into an array of lists Cola_Reb 6 1,663 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
Question how to write a function that accepts a 1D array as a parameter in Python SuperNinja3I3 1 1,552 Jul-02-2022, 01:55 PM
Last Post: Larz60+
  replace sets of values in an array without using loops paul18fr 7 1,631 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  how to parse this array with pandas? netanelst 1 1,299 May-17-2022, 12:42 PM
Last Post: netanelst
  semantics of comma inside array brackets usercat123 2 1,324 Apr-23-2022, 09:08 AM
Last Post: usercat123
  RandomForest --ValueError: setting an array element with a sequence JaneTan 0 1,707 Sep-08-2021, 02:12 AM
Last Post: JaneTan
  Keep inner Values of 2D array timste 0 1,543 Jul-26-2021, 09:04 AM
Last Post: timste

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020