简体   繁体   English

如何在libsvm中使用svm_model函数'predict'?

[英]How to use the function 'predict' of svm_model in libsvm?

In recent version of libsvm(v3.17 2013.04.01), the method 'predict' in class 'svm_model' has been removed. 在最新版本的libsvm(v3.17 2013.04.01)中,类'svm_model'中的'predict'方法已被删除。

The alternative method seems to be method 'svm_predict' in module 'svmutil'. 替代方法似乎是模块'svmutil'中的方法'svm_predict'。 But I can't understand the parameter data(y,x) of this method. 但我无法理解这种方法的参数数据(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. """ 

"y" are the labels and correspond with the datapoint in "x" “y”是标签,与“x”中的数据点对应

Here is an example of something I did last month: 这是我上个月做的一个例子:

#!/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在Python中使用在matlab中生成的svm_model? - Is it possible to use in Python the svm_model, generated in matlab? 如何使用Libsvm计算“准确性”-SVM_Predict.exe - How is “accuracy” calculated using Libsvm - SVM_Predict.exe 如何从svm_model获取支持向量和rho值(在Python中)? - How to get support vectors and rho values from svm_model (in Python)? python libsvm:使用函数:svm_predict(),输出“p_val”是什么意思 - python libsvm: used function: svm_predict(), what means with output “p_val” tensorflow tf.contrib.learn.SVM如何重新加载训练后的模型并使用预测对新数据进行分类 - How tensorflow tf.contrib.learn.SVM reload trained model and use predict to classify new data 如何从Linear SVM手动使用拟合模型进行预测? - How to predict using the fit model from Linear SVM manually? 如何在 SVM 情绪分析中使用 predict_proba - How to use predict_proba at SVM Sentiment Analysis 如何将 SVM 分类器与 keras CNN model 一起使用? - How to use SVM classifier with keras CNN model? 如何加载用 saved_model 保存的 tensorflow keras model 以使用预测 function? - How to load a tensorflow keras model saved with saved_model to use the predict function? OSX上PyBrain上的libsvm用于SVM - libsvm on PyBrain on OSX for an SVM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM