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>是的,我在使用“CountVectorizer”时也有过类似的担心。 当我去掉了对测试数据的附加拟合,并且只使用了基于对训练数据的拟合的“转换”方法时,它就像宝石一样工作。</p> <p>如果共享它,有助于社区在使用测试数据预测结果时考虑类似的问题。</p> <p>谢谢, 夏比尔·贾米尔</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
2 回答
python中两个字符串上的异或操作数?
2 回答
Python中两个字符串中的类似句子
4 回答
Python中两个字符串之间的Hamming距离
3 回答
python中两个字符串之间的匹配模式
10 回答
python中两个字符串之间的按位或
2 回答
python中两个字符串之间的数据(字节)切片
5 回答
python中两个字符串之间的模式
6 回答
python中两个字符串作为子字符串的区别
4 回答
Python中两个字符串元组的比较
2 回答
Python中两个字符串列表中的公共字符串
9 回答
python中两个字符串的Anagram测试
6 回答
Python中两个字符串的正则匹配
10 回答
python中两个字符串的笛卡尔乘积
6 回答
Python中两个字符串相似性的比较
1 回答
python中两个字符串语义相似度的求法
1 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
4 回答
Python中两个对数方程之间的插值和平滑数据
4 回答
Python中两个对象之间的And/Or运算符
8 回答
python中两个嵌套字典中相似键的和值
9 回答