libsvm预测方法混乱
我对 libsvm 中的 svm_predict() 方法有疑问。
自述文件有以下快速入门示例代码:
>>> y, x = [1,-1], [{1:1, 3:1}, {1:-1,3:-1}]
>>> prob = svm_problem(y, x)
>>> param = svm_parameter('-c 4 -b 1')
>>> m = svm_train(prob, param)
>>> p_label, p_acc, p_val = svm_predict(y, x, m)
现在我明白 y 是与 x 中的词典关联的类别列表。我也理解 svm_train 部分。
没有意义的部分是,在 svm_predict 中,我需要提供 y 中的“真实值”以及 x 中的测试数据。我认为这个想法是我不提前知道测试数据的分类。
如果我的训练数据是:
y = [1, 2, 3]
x = [{1:1}, {1:10}, {1:20}]
但我的测试数据是:
z = [{1:4}, {1:12}, {1:19}]
那么为什么我需要将 z 的真实值传递到 svm_predict() 中,例如:
a, b, c = svm_predict(y, z, m)
我不会知道 z 的真实值——这就是预测的目的。当我执行预测时,我应该为 y 输入任意分类值,还是我完全遗漏了一些东西?
谢谢大家
I have a question about the svm_predict() method in libsvm.
The README has this quickstart example code:
>>> y, x = [1,-1], [{1:1, 3:1}, {1:-1,3:-1}]
>>> prob = svm_problem(y, x)
>>> param = svm_parameter('-c 4 -b 1')
>>> m = svm_train(prob, param)
>>> p_label, p_acc, p_val = svm_predict(y, x, m)
Now I understand that y is a list of categories that are associated with the dictionaries in x. I also understand the svm_train part.
The part that does not make sense is that in svm_predict, I am required to provide the 'true values' from y, along with the test data in x. I thought the idea was that I do not know the classifications of the test data ahead of time.
if my training data is:
y = [1, 2, 3]
x = [{1:1}, {1:10}, {1:20}]
but my test data is:
z = [{1:4}, {1:12}, {1:19}]
Then why am I required to pass in true values of z into svm_predict() like:
a, b, c = svm_predict(y, z, m)
I'm not going to know the true values for z--that's what the prediction is for. Should I just put arbitrary classification values for y when I perform a prediction, or am I completely missing something?
Thanks all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在进行样本外测试,它会使用真实标签为您提供准确性统计数据。
如果您“在线”运行它,即您实际上没有真正的标签,则只需输入
[0]*len(z)
而不是y
It uses the true labels to give you accuracy statistics in case you are doing an out-of-sample test.
If you are running it "online", i.e. you actually don't have the true labels, then just put
[0]*len(z)
instead ofy
您可能会考虑使用
http://scikit-learn.sourceforge.net/
它有一个很棒的 python 绑定libsvm 的
You might consider using
http://scikit-learn.sourceforge.net/
That has a great python binding of libsvm