【问题标题】:How to use the function 'predict' of svm_model in libsvm?如何在 libsvm 中使用 svm_model 的函数 'predict'?
【发布时间】:2014-01-21 01:37:19
【问题描述】:

在最新版本的 libsvm(v3.17 2013.04.01) 中,类 'svm_model' 中的方法 'predict' 已被删除。

替代方法似乎是模块“svmutil”中的方法“svm_predict”。但是看不懂这个方法的参数data(y,x)。

def svm_predict(y, x, m, options=""):

"""
svm_predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals)

Predict data (y, x) with the SVM model m. 
options: 
    -b probability_estimates: whether to predict probability estimates, 
        0 or 1 (default 0); for one-class SVM only 0 is supported.
    -q : quiet mode (no outputs).

The return tuple contains
p_labels: a list of predicted labels
p_acc: a tuple including  accuracy (for classification), mean-squared 
       error, and squared correlation coefficient (for regression).
p_vals: a list of decision values or probability estimates (if '-b 1' 
        is specified). If k is the number of classes, for decision values,
        each element includes results of predicting k(k-1)/2 binary-class
        SVMs. For probabilities, each element contains k values indicating
        the probability that the testing instance is in each class.
        Note that the order of classes here is the same as 'model.label'
        field in the model structure.
"""

【问题讨论】:

    标签: python api svm libsvm


    【解决方案1】:

    “y”是标签,对应“x”中的数据点

    这是我上个月做的一个例子:

    #!/usr/bin/python
    from svmutil import *
    
    model = svm_load_model("train_yesterday.model")
    
    values=[{1:1.37599, 2:1.37597, 3:1.37597, 4:1.37587, 5:1.37586}]
    newcurve = []
    
    for j in range(1,121):
        a,b,val = svm_predict([1],values,model)
        newval = val[0][0]
    
        for i in range(1,5):
            values[0][i] = values[0][i+1]
        values[0][5] = newval
    

    【讨论】:

    • 如果我们要预测“X”中点的分类,为什么要输入对应的“y”?这不正是我们要寻找的吗?
    • @mxdg 如果你想得到模型的精度是可选的,否则你可以忽略它们。
    猜你喜欢
    • 2013-12-19
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2013-02-20
    • 2015-01-16
    • 2012-01-23
    • 1970-01-01
    相关资源
    最近更新 更多