Python中文
首页
教程
问答
标签
搜索
登录
注册
Python scikit svm“ValueError:X每个示例有62个特性;预期为337”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>玩弄Python的scikit-SVM线性支持向量分类,当我试图进行预测时遇到了一个错误:</p> <pre><code>ten_percent = len(raw_routes_data) / 10 # Training training_label = all_labels[ten_percent:] training_raw_data = raw_routes_data[ten_percent:] training_data = DictVectorizer().fit_transform(training_raw_data).toarray() learner = svm.LinearSVC() learner.fit(training_data, training_label) # Predicting testing_label = all_labels[:ten_percent] testing_raw_data = raw_routes_data[:ten_percent] testing_data = DictVectorizer().fit_transform(testing_raw_data).toarray() testing_predictions = learner.predict(testing_data) m = metrics.classification_report(testing_label, testing_predictions) </code></pre> <p>原始数据表示为Python字典,其中包含各种旅行选项的到达时间类别和天气数据的类别:</p> <pre><code>{'72_bus': '6.0 to 11.0', 'uber_eta': '2.0 to 3.5', 'tweet_delay': '0', 'c_train': '1.0 to 4.0', 'weather': 'Overcast', '52_bus': '16.0 to 21.0', 'uber_surging': '1.0 to 1.15', 'd_train': '17.6666666667 to 21.8333333333', 'feels_like': '27.6666666667 to 32.5'} </code></pre> <p>当我训练并拟合训练数据时,我对90%的数据使用字典矢量器,并将其转换为数组。</p> <p>提供的测试标签表示为:</p> <pre><code>[1,2,3,3,1,2,3, ... ] </code></pre> <p>当我试图用线性预测来预测我被告知:</p> <pre><code>ValueError: X has 27 features per sample; expecting 46 </code></pre> <p>我错过了什么?显然,这是我拟合和转换数据的方式。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>问题是,您为train和test创建并安装了不同的<code>DictVectorizer</code>。</p> <p>您应该使用列车数据创建并只适合一个<code>DictVectorizer</code>,并在测试数据上使用此对象的<code>transform</code>方法来创建测试数据的特征表示。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
6 回答
Jupyter运行不同版本的卸载库?
10 回答
Jupyter运行指定的键盘快捷键
3 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
10 回答
Jupyter重新加载自定义样式
3 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
10 回答
jupyter错误:无法在随机林中将决策树视为png
10 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
6 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
3 回答
Jupyter隐藏数据帧索引,但保留原始样式
10 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
5 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
8 回答
Jupy上Python的读/写访问问题
6 回答
jupy上没有模块cv
10 回答
Jupy上的排序错误
6 回答
Jupy中bqplot图形的紧凑布局
3 回答
Jupy中matplotlib plot的连续更新
3 回答
Jupy中Numpy函数的文档
3 回答
Jupy中Pandas的自动完成问题
2 回答
jupy中Qt后端的Matplotlib动画
4 回答