Scikit-用于SVM的3D特征阵列 [英] Scikit - 3D feature array for SVM

查看:177
本文介绍了Scikit-用于SVM的3D特征阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在scikit中训练SVM.我正在跟踪该示例,并尝试将其调整为我的3d特征向量. 我从 http://scikit-learn.org/stable/modules/页面尝试了该示例svm.html 它跑了过去.修正错误时,我回到了教程设置中,发现了这一点:

I am trying to train an SVM in scikit. I am following the example and tried to adjust it to my 3d feature vectors. I tried the example from the page http://scikit-learn.org/stable/modules/svm.html and it ran through. While bugfixing I came back to the tutorial setup and found this:

X = [[0, 0], [1, 1],[2,2]]
y = [0, 1,1]
clf = svm.SVC()
clf.fit(X, y) 

同时工作

X = [[0, 0,0], [1, 1,1],[2,2,2]]
y = [0, 1,1]
clf = svm.SVC()
clf.fit(X, y)

失败: ValueError: X.shape[1] = 2 should be equal to 3, the number of features at training time

这是怎么了?这只是一个额外的维度... 谢谢,

what is wrong here? It's only one additional dimension... Thanks, El

推荐答案

运行您后面的代码对我有用:

Running your latter code works for me:

>>> X = [[0,0,0], [1,1,1], [2,2,2]]
>>> y = [0,1,1]
>>> clf = svm.SVC()
>>> clf.fit(X, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
  kernel='rbf', max_iter=-1, probability=False, shrinking=True, tol=0.001,
  verbose=False)

当您使用kernel="precomputed"在SVM对象上调用.predict()时,该错误消息似乎应该实际上发生.是这样吗?

That error message seems like it should actually happen when you're calling .predict() on an SVM object with kernel="precomputed". Is that the case?

这篇关于Scikit-用于SVM的3D特征阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆