标记编码报错ValueError: bad input shape ()
《Python机器学习经典实例》2.9小节中,想自己动手实践汽车特征评估质量,所以需要对数据进行预处理,其中代码有把字符串标记编码为对应的数字,如下代码
input_data = ['vhigh', 'vhigh', '2', '2', 'small', 'low']
input_data_encoded = [-1] * len(input_data)
for i,item in enumerate(input_data):
input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
报错:
Traceback (most recent call last):
File "E:/17770426925/PythonLeaning/Machine-Learning/classifier/classifier.py", line 255, in <module>
input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\label.py", line 147, in transform
y = column_or_1d(y, warn=True)
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 562, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()
所以由此看出,是label_encoder[i].transform(input_data[i])中input_data[i]输入的数值形式不对,需要将其改变成list,所以可对该代码进行改进:
for i, item in enumerate(input_data):
labels=[]
labels.append(input_data[i])
input_data_encoded[i] = int(label_encoder[i].transform(labels))
标记编码报错ValueError: bad input shape ()的更多相关文章
- sklearn里计算roc_auc_score,报错ValueError: bad input shape
用sklearn的DecisionTreeClassifer训练模型,然后用roc_auc_score计算模型的auc.代码如下 clf = DecisionTreeClassifier(criter ...
- keras 报错 ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(5001, 128), dtype=float32)'
在服务器上训练并保存模型,复制到本地之后load_model()报错: ValueError: Tensor conversion requested dtype int32 for Tensor w ...
- matplotlib.pyplot import报错: ValueError: _getfullpathname: embedded null character in path
Environment: Windows 10, Anaconda 3.6 matplotlib 2.0 import matplotlib.pyplot 报错: ValueError: _getfu ...
- dbfread报错ValueError错误解决方法
问题 我在用dbfread处理.dbf数据的时候出现了报错 ValueError("could not convert string to float: b'.'",) 然后查找. ...
- Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’
一.部署 Django 到远程 Linux 服务器 利用 xshell 通过 ssh 连接到 Linux服务器,常规的启动命令是 python3 manage.py runserver 但是,关闭 x ...
- 记一次用python 的ConfigParser读取配置文件编码报错
记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...
- moviepy音视频剪辑VideoClip类fl_image方法image_func报错ValueError: assignment destination is read-only解决办法
☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑模块的视频剪辑基类VideoClip的fl_image方法用于进行对剪辑帧数据进行变换. 调用语法:fl_image(self, im ...
- tensorflow-TFRecord报错ValueError: Protocol message Feature has no "feature" field.
编写代码用TFRecord数据结构存储数据集信息是报错:ValueError: Protocol message Feature has no "feature" field.或和 ...
- datetime.strptime格式转换报错ValueError
今天遇到一个报错:ValueError: time data '2018-10-10(Wednesday) AM0:50' does not match format '%Y-%m-%d(%A) %p ...
随机推荐
- 西汉姆VS利物浦,铁锤『拳』出击,打回原『菱』形
一.铁锤,还是铁桶? 铁锤帮西汉姆今晚摆出4-2-3-1对阵红军利物浦的4-3-3 ,阿勒戴斯曾在主场2-1战胜赫尔城时被球迷嘘,嫌他的足球太过丑陋『2010年的时候贝尼特斯也曾经诟病阿勒戴斯带队 ...
- bootstrap table通过ajax获取后台数据展示在table
1. 背景 bootstrap table 默认向后台发送语法的dataType为 json,但是为了解决跨域问题我们需要将dataType改为jsonp,这时就需要修改bootstrap table ...
- 创建一个dynamics 365 CRM online plugin (十二) - Asynchronous Plugins
这篇是plugin的终结. 通过之前的11期我们应该发现了plugin其实学习起来不难. async plugin 是把plugin的功能async run起来. e.g. 我们之前做过的preOp ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total ...
- shell小计
NF 是每行的字段数 (NF==8)标识每行有8个字段,当前记录中的字段个数,就是有多少列NR 是总共读取了多少行 (NR==2)第二行的意思,已经读出的记录数,就是行号,从 1 开始 awk简单使 ...
- 2018.10.2 Eclipse中如何测地修改一个we项目步骤
找到项目的web.xml文件 大概的路径如下: 修改xml文件中的display-name 节点的值 下一步就是切换工作目录 显示的效果 打开最后一个文件修改 接下来找到这个文件 是部署的时候用的 运 ...
- 02_Linux 终端命令格式
01. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相应功能的英文单词或单词的缩写 [-options]:选项,可用来对命令进行控制,也 ...
- AngularJS 使用 even 和 odd 表格
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- dedecms基础整理,
需求3: 在添加某个商品的时候,我们希望多一个信息,就是付费方式,还希望多一个邮资信息,我们又该怎样处理? 引出修改内容模型的问题 每个模型的字段管理的所有信息 都属于附加表. 步骤: 点击 核心-& ...