valueerror:expected 2D Array, got 1D array instead:

Source: Internet
Author: User
Tags svm

1. You could be the same

 
test_prediction = svc.predict (hog_features.reshape) modified before 
modification 


2. This possibility

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, one]

plt.scatter (x,y)
plt.show () C11/>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])
is not meet the 2D does not involve reshape

Amended to

Print (Clf.predict ([[0.58,0.76]]))


3. The situation you have encountered. Fit_transform (Dataset3_preds.label) error

: reference


Mainly is the package version of the update caused by the above problem, we according to the above error prompts corresponding to find the line of error code:

#修改前
Dataset3_preds.label = Minmaxscaler (copy=true,feature_range= (0,1)). Fit_transform (Dataset3_preds.label)

For example, a data format of [1, 2, 3, 4] would be an error, if this line of data is converted to [[1], [2], [3], [4]]

Dataset3_preds.label = Minmaxscaler (copy=true,feature_range= (0,1)). Fit_transform (Dataset3_preds.label.reshape (- 1,1) #修改后


Run the program again, error elimination.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.