ValueError Expected 2D array got 1D array instead

本文分享了实用的人工智能教程资源,同时提供了在使用sklearn进行机器学习预测时常见的reshape错误修正方法,包括如何正确调整数据维度以适应模型预测。

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

1.你也可能是这种

修改前 test_prediction = svc.predict(hog_features.reshape) 修改后 test_prediction = svc.predict(hog_features.reshape(1,-1)) 


2.这种可能

import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import stylestyle.use("ggplot")from sklearn import svmx = [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]))
就是没有满足2D都不涉及reshape

修改为

print(clf.predict([[0.58,0.76]]))


3.自己遇到的情况.fit_transform(dataset3_preds.label)出错

参考


主要是工具包版本更新造成的,面对上面问题,我们根据上面错误的提示相应的找出出错的那行代码:

#修改前dataset3_preds.label = MinMaxScaler(copy=True,feature_range=(0,1)).fit_transform(dataset3_preds.label)

例如数据格式为[1,  2, 3, 4]就会出错,如果把这行数据转换成[[1], [2], [3], [4]]

dataset3_preds.label = MinMaxScaler(copy=True,feature_range=(0,1)).fit_transform(dataset3_preds.label.reshape(-1,1))#修改后


再运行程序,错误消除。




           

给我老师的人工智能教程打call!http://blog.youkuaiyun.com/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值