解决ValueError: bad input shape (xxxx, x)
下面看一段机器学习代码:
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import cross_val_score
iris=datasets.load_iris()
x_train,y_train,x_test,y_test = train_test_split(iris.data,iris.target,test_size=0.4,random_state=0)
clf=GaussianNB()
clf.fit(x_train,y_train)
使用高斯朴素贝叶斯模型对鸢尾花数据集进行训练,但运行时出现以下问题:
查看错误原因,提示为值错误,这个错误发生在模型训练位置,并且模型训练语句没有错误,那么就是传给模型训练的数据发生了错误(x_train,y_train)!!!我们返回去检查这两个数据集,发现使用train_test_split在分割数据集时,我们将数据集顺序写错了,正确的数据集顺序为:x_train,x_test,y_train,y_test,正是由于这个正确的顺序,才能分割正确的数据集与测试集,大部分人认为这个数据集没有顺序,下面看一下train_test_split的常规用法:
X_train,X_test, y_train, y_test =sklearn.model_selection.train_test_split(train_data,train_target,test_size=0.4, random_state=0)
# train_data:所要划分的样本特征集
# train_target:所要划分的样本结果
# test_size:样本占比,如果是整数的话就是样本的数量
# random_state:是随机数的种子。
因此千万不要忽略训练集与测试集的顺序!
解决ValueError: bad input shape (xxxx, x)相关推荐
- 成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891] 目录 解决问题 解决思路 解 ...
- 解决ValueError: Found input variables with inconsistent numbers of samples
问题描述:主要是运行中提示 ValueError: Found input variables with inconsistent numbers of samples 百度可知 :参考 成功解决Va ...
- ValueError: Found input variables with inconsistent numbers of samples
解决ValueError: Found input variables with inconsistent numbers of samples 问题背景 使用python的sklearn库进行线性回 ...
- python报错ValueError: Must pass 2-d input. shape=(5, 1, 10)解决方案
1.承接上一篇博文,上文提到append()函数中的参数ignore_index=True,如果加上该参数,是a.append(b,ignore_index=True),数据不支持的情况下会报错&qu ...
- 成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2)
成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2) 目录 解决问题 解决思路 解决方法 解决问题 Valu ...
- 成功解决ValueError: Could not interpret input day
成功解决ValueError: Could not interpret input 'day' 目录 解决问题 解决思路 解决方法 解决问题 ValueError: Could not interpr ...
- 成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor Placeholder:0 , which has shape
成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor 'Placeholder:0', which has shape '( ...
- 成功解决ValueError: Cannot feed value of shape (80, 15, 1, 1) for Tensor 'Placeholder_1:0', which has sh
成功解决ValueError: Cannot feed value of shape (80, 15, 1, 1) for Tensor 'Placeholder_1:0', which has sh ...
- 成功解决ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
成功解决ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). 目录 解决问题 解决方法 ...
最新文章
- 10 words and phrases that shouldn’t be on your résumé
- DS博客作业07--查找
- 关于 HeartBleed 安全漏洞的 2 张漫画
- VTK:Rendering之DiffuseSpheres
- l洛谷P4779 【模板】单源最短路径(标准版)(dijkstra)
- vc mysql_vc6.0连接mysql数据库
- 动态资源Servlet接口
- html背景定位,css background-position center left right top bottom代表意思
- [PAL规范]SAP HANA PAL演绎推理算法Apriori编程规范APRIORIRULE
- ollections 模块之OrderedDict
- .netcore excel导出回车换行_必须掌握的回车键Enter应用技巧,100%干货
- raw socket
- android+nfc+助手,NFC助手app
- 华为S9306交换机版本升级及补丁安装步骤
- 成功路上并不拥挤 因为坚持的人不多
- 对SG函数(Sprague-Garundy函数)及其应用的简单解释与证明
- 源码多多-Discuz x2.5 论坛防灌水机制分析和设置方法
- 不经一番寒彻骨,怎得梅花扑鼻香,墙都不扶就服你
- Ubuntu调整分辨率至1920*1080
- [BZOJ3698]XWW的难题(有源汇有上下界的最大流)