Felomeng翻译:libsvm2.88之函数库的使用

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">这些函数和结构都在头文件“</span><span style=""><span style="font-family: Times New Roman;">svm.h</span></span><span style="">”中有声名。你需要在你的</span><span style=""><span style="font-family: Times New Roman;">C/C++</span></span><span style="">源文件中添加</span><span style=""><span style="font-family: Times New Roman;">#include “svm.h”</span></span><span style="">语句,在连接时需要将你的程序与</span><span style=""><span style="font-family: Times New Roman;">svm.cpp</span></span><span style="">连接。具体使用方法可以参考“</span><span style=""><span style="font-family: Times New Roman;">svm-train.c</span></span><span style="">”和“</span><span style=""><span style="font-family: Times New Roman;">svm-predict.c</span></span><span style="">”的使用示例。在文件</span><span style=""><span style="font-family: Times New Roman;">svm.h</span></span><span style="">中使用</span><span style=""><span style="font-family: Times New Roman;">LIBSVM_VERSION</span></span><span style="">定义了版本号,以便读者查阅。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">在对测试数据进行分类之前,需要先使用训练数据建立一个支持向量模型。模型可以以文件的形式存储以备以后使用。一旦建立好了支持向量机模型,就可以用它来对新的数据进行分类了。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">这个函数根据给定的参数和训练数据构建并返回一个支持向量机模型。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">结构体</span><span style=""><span style="font-family: Times New Roman;">svm_problem</span></span><span style="">将问题形式化:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">struct svm_problem</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int l;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double *y;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">struct svm_node **x;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>};</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">其中“</span><span style=""><span style="font-family: Times New Roman;">l</span></span><span style="">”表示训练数据的实例数,而“</span><span style=""><span style="font-family: Times New Roman;">y</span></span><span style="">”是一个数组,用于存放它们的目标值。(类型值用整型数据,回归值用实数)“</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">”是一个数组指针,每一个指针指向一个稀疏的训练向量(即一个</span><span style=""><span style="font-family: Times New Roman;">svm_node</span></span><span style="">数组)。</span><span lang="EN-US"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">例如,如果我们有如下的训练数据:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">LABEL</span><span lang="EN-US"><span style=""> </span></span><span style="">ATTR1</span><span lang="EN-US"><span style=""> </span></span><span style="">ATTR2</span><span lang="EN-US"><span style=""> </span></span><span style="">ATTR3</span><span lang="EN-US"><span style=""> </span></span><span style="">ATTR4</span><span lang="EN-US"><span style=""> </span></span><span style="">ATTR5</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>-----<span style=""> </span>-----<span style=""> </span>-----<span style=""> </span>-----<span style=""> </span>-----<span style=""> </span>-----</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>1<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0.1<span style=""> </span><span style=""> </span>0.2<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>2<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0.1<span style=""> </span><span style=""> </span>0.3<span style=""> </span>-1.2<span style=""> </span><span style=""> </span>0</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>1<span style=""> </span><span style=""> </span>0.4<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>2<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>0.1<span style=""> </span><span style=""> </span>0<span style=""> </span><span style=""> </span>1.4<span style=""> </span><span style=""> </span>0.5</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>3<span style=""> </span>-0.1<span style=""> </span>-0.2<span style=""> </span><span style=""> </span>0.1<span style=""> </span><span style=""> </span>1.1<span style=""> </span><span style=""> </span>0.1</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">于是</span><span style=""><span style="font-family: Times New Roman;">svm_problem</span></span><span style="">的构成如下:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small; font-family: Times New Roman;">l = 5</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small; font-family: Times New Roman;">y -&gt; 1 2 1 2 3</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small; font-family: Times New Roman;">x -&gt; [ ] -&gt; (2,0.1) (3,0.2) (-1,?)</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span><span style=""></span>[ ] -&gt; (2,0.1) (3,0.3) (4,-1.2) (-1,?)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span><span style=""></span>[ ] -&gt; (1,0.4) (-1,?)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span><span style=""></span>[ ] -&gt; (2,0.1) (4,1.4) (5,0.5) (-1,?)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span><span style=""></span>[ ] -&gt; (1,-0.1) (2,-0.2) (3,0.1) (4,1.1) (5,0.1) (-1,?)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">其中(索引,值)存储在结构“</span><span style=""><span style="font-family: Times New Roman;">svm_node</span></span><span style="">”中:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">struct svm_node</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int index;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double value;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>};</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">当索引为</span><span style=""><span style="font-family: Times New Roman;">-1</span></span><span style="">时表示已经到达向量的末端。注意索引必须“升序”排列。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">结构体</span><span style=""><span style="font-family: Times New Roman;">svm_parameter</span></span><span style="">描述了一个支持向量机的参数:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">struct svm_parameter</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int svm_type;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int kernel_type;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int degree;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for poly */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double gamma;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for poly/rbf/sigmoid */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double coef0;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for poly/sigmoid */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">/* these are for training only */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double cache_size; /* in MB */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double eps;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* stopping criteria */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double C;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for C_SVC, EPSILON_SVR, and NU_SVR */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int nr_weight;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for C_SVC */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int *weight_label;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for C_SVC */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double* weight;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for C_SVC */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double nu;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for NU_SVC, ONE_CLASS, and NU_SVR */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">double p;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* for EPSILON_SVR */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int shrinking;</span><span lang="EN-US"><span style=""> </span></span><span style="">/* use the shrinking heuristics */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">int probability; /* do probability estimates */</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span>};</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">svm_type</span></span><span style="">可以是</span><span style=""><span style="font-family: Times New Roman;">C_SVC</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">NU_SVC</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">ONE_CLASS</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">EPSILON_SVR</span></span><span style="">或</span><span style=""><span style="font-family: Times New Roman;">NU_SVR</span></span><span style="">其中的一种。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">C_SVC:</span><span lang="EN-US"><span style=""> </span></span><span style="">C-SVM </span></span><span style="">分类</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">NU_SVC:</span><span lang="EN-US"><span style=""> </span></span><span style="">nu-SVM </span></span><span style="">分类</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">ONE_CLASS:</span><span lang="EN-US"><span style=""> </span></span><span style="">one-class-SVM</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">EPSILON_SVR:</span><span lang="EN-US"><span style=""> </span></span><span style="">epsilon-SVM</span></span><span style="">回归</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">NU_SVR:</span><span lang="EN-US"><span style=""> </span></span><span style="">nu-SVM</span></span><span style="">回归</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">kernel_type</span></span><span style="">可以是</span><span style=""><span style="font-family: Times New Roman;">LINEAR</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">POLY</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">RBF</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">SIGMOID</span></span><span style="">其中一种。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">LINEAR:</span><span lang="EN-US"><span style=""> </span></span><span style="">u'*v</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">POLY:</span><span lang="EN-US"><span style=""> </span></span><span style="">(gamma*u'*v + coef0)^degree</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">RBF:</span><span lang="EN-US"><span style=""> </span></span><span style="">exp(-gamma*|u-v|^2)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">SIGMOID:</span><span lang="EN-US"><span style=""> </span></span><span style="">tanh(gamma*u'*v + coef0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">PRECOMPUTED:</span></span><span style="">训练集文件中的核心值</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">cache_size</span></span><span style="">是核心缓存的大小,单位为</span><span style=""><span style="font-family: Times New Roman;">MB</span></span><span style="">。</span><span style=""><span style="font-family: Times New Roman;">C</span></span><span style="">是违背约束成本(惩罚值)。</span><span style=""><span style="font-family: Times New Roman;">eps</span></span><span style="">是结束条件。(一般地,我们在</span><span style=""><span style="font-family: Times New Roman;">nu-SVC</span></span><span style="">模型中使用</span><span style=""><span style="font-family: Times New Roman;">0.00001</span></span><span style="">,在其它模型中使用</span><span style=""><span style="font-family: Times New Roman;">0.001</span></span><span style="">)。</span><span style=""><span style="font-family: Times New Roman;">nu</span></span><span style="">是</span><span style=""><span style="font-family: Times New Roman;">nu-SVM</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">nu-SVR</span></span><span style="">与</span><span style=""><span style="font-family: Times New Roman;">one-class-SVM</span></span><span style="">中的一个参数。</span><span style=""><span style="font-family: Times New Roman;">p </span></span><span style="">是</span><span style=""><span style="font-family: Times New Roman;">epsilon-SVM</span></span><span style="">回归中对</span><span style=""><span style="font-family: Times New Roman;">epsilon</span></span><span style="">不敏感函数的</span><span style=""><span style="font-family: Times New Roman;">epsilon</span></span><span style="">值。</span><span style=""><span style="font-family: Times New Roman;">shirnking = 1</span></span><span style="">表示使用压缩,否则</span><span style=""><span style="font-family: Times New Roman;"> = 0</span></span><span style="">。</span><span style=""><span style="font-family: Times New Roman;"> probability = 1</span></span><span style="">表示得到带概率信息的模型,否则</span><span style=""><span style="font-family: Times New Roman;"> = 0</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">nr_weight</span></span><span style="">、</span><span style=""><span style="font-family: Times New Roman;">weight_label</span></span><span style="">和</span><span style=""><span style="font-family: Times New Roman;">weight</span></span><span style="">(权重)用于改变某些类的惩罚因子(如果一个类的权重不变,则将权重值设定为</span><span style=""><span style="font-family: Times New Roman;">1</span></span><span style="">)这在使用不均衡输入数据或使用不均匀错误成本训练分类器时尤其有用。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">nr_weight</span></span><span style="">是数组</span><span style=""><span style="font-family: Times New Roman;">weight_label</span></span><span style="">和</span><span style=""><span style="font-family: Times New Roman;">weight</span></span><span style="">中的元素个数。每个</span><span style=""><span style="font-family: Times New Roman;">weight[i]</span></span><span style="">对应一个</span><span style=""><span style="font-family: Times New Roman;">weight_label[i]</span></span><span style="">,表示类</span><span style=""><span style="font-family: Times New Roman;">weight_label[i]</span></span><span style="">的惩罚是由因子</span><span style=""><span style="font-family: Times New Roman;">weight[i]</span></span><span style="">确定的。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">如果不想改变任何类的惩罚因子,那么只需要将</span><span style=""><span style="font-family: Times New Roman;">nr_weight</span></span><span style="">设定为</span><span style=""><span style="font-family: Times New Roman;">0</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">*</span></span><span style="">注意</span><span style=""><span style="font-family: Times New Roman;">*</span></span><span style="">因为</span><span style=""><span style="font-family: Times New Roman;">svm_model</span></span><span style="">含有指向</span><span style=""><span style="font-family: Times New Roman;">svm_problem</span></span><span style="">的指针,如果仍要使用由</span><span style=""><span style="font-family: Times New Roman;">svm_train()</span></span><span style="">产生的</span><span style=""><span style="font-family: Times New Roman;">svm_model</span></span><span style="">,那么就不要释放</span><span style=""><span style="font-family: Times New Roman;">svm_problem</span></span><span style="">的内存。</span><span lang="EN-US"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">*</span></span><span style="">注意</span><span style=""><span style="font-family: Times New Roman;">*</span></span><span style="">为了避免错误的参数,在调用</span><span style=""><span style="font-family: Times New Roman;">svm_train()</span></span><span style="">之前应该先调用</span><span style=""><span style="font-family: Times New Roman;">svm_check_parameter()</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">double svm_predict(const struct svm_model *model,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small; font-family: Times New Roman;">const struct svm_node *x);</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">在给定模型的前提下,这个函数可以用来对测试向量</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">进行分类或回归。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">分类模型返回的是</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">的预测类。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">回归模型返回使用该模型计算所得的</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">函数值。</span><span style=""><span style="font-family: Times New Roman;">one-class</span></span><span style="">模型返回</span><span style=""><span style="font-family: Times New Roman;">+1</span></span><span style="">或</span><span style=""><span style="font-family: Times New Roman;">-1</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">void svm_cross_validation(const struct svm_problem *prob,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span></span><span style="">const struct svm_parameter *param, int nr_fold, double *target);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">这个函数用于交叉验证。数据会分成</span><span style=""><span style="font-family: Times New Roman;">nr_fold</span></span><span style="">个部分。在给定的参数下,顺序地对每一部分数据用其余部分数据训练成的模型进行验证。在验证过程中,预测标签(所有</span><span style=""><span style="font-family: Times New Roman;">prob</span></span><span style="">的实例)存放到一个名为</span><span style=""><span style="font-family: Times New Roman;">target</span></span><span style="">(目标)的数组。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">svm_prob</span></span><span style="">的格式与</span><span style=""><span style="font-family: Times New Roman;">svm_train()</span></span><span style="">的相同。</span><span lang="EN-US"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">int svm_get_svm_type(const struct svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">这个函数用于确定模型的</span><span style=""><span style="font-family: Times New Roman;">svm_type</span></span><span style="">。可能的</span><span style=""><span style="font-family: Times New Roman;">svm_type</span></span><span style="">值已在</span><span style=""><span style="font-family: Times New Roman;">svm.h</span></span><span style="">中定义。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">int svm_get_nr_class(const svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">对于分类模型,本函数用于得到类的数量。回归或</span><span style=""><span style="font-family: Times New Roman;">one-class</span></span><span style="">模型的返回值是</span><span style=""><span style="font-family: Times New Roman;">2</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">void svm_get_labels(const svm_model *model, int* label)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">对于分类模型,这个函数输出名称标签到一个名为</span><span style=""><span style="font-family: Times New Roman;">label</span></span><span style="">的数组。对于回归或</span><span style=""><span style="font-family: Times New Roman;">one-class</span></span><span style="">模型,</span><span style=""><span style="font-family: Times New Roman;">label</span></span><span style="">的值保护不变。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">double svm_get_svr_probability(const struct svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">对于带有概率信息的回归模型,此函数将输出一个值</span><span style=""><span style="font-family: Times New Roman;">sigma&gt;0</span></span><span style="">。对于测试数据,我们考虑概率模型:目标值</span><span style=""><span style="font-family: Times New Roman;"> = </span></span><span style="">预测值</span><span style=""><span style="font-family: Times New Roman;"> + z</span></span><span style="">,</span><span style=""><span style="font-family: Times New Roman;">z</span></span><span style="">:拉普拉斯分布</span><span style=""><span style="font-family: Times New Roman;">e^(-|z|/sigma)/(2sigma)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">如果不是</span><span style=""><span style="font-family: Times New Roman;">svr</span></span><span style="">模型,或者不含有需要的信息,则返回</span><span style=""><span style="font-family: Times New Roman;">0</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">void svm_predict_values(const svm_model *model,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span><span style=""> </span></span><span style="">const svm_node *x, double* dec_values)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">在给定模型的前提下,这个函数可以用来给出测试向量</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">的决策值。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">对于有</span><span style=""><span style="font-family: Times New Roman;">nr_class</span></span><span style="">个类的分类模型,这个函数给出</span><span style=""><span style="font-family: Times New Roman;">nr_class*(nr_class-1)/2</span></span><span style="">个决策值,并存到数组</span><span style=""><span style="font-family: Times New Roman;">dec_values</span></span><span style="">中,其中</span><span style=""><span style="font-family: Times New Roman;">nr_class</span></span><span style="">可以通过函数</span><span style=""><span style="font-family: Times New Roman;">svm_get_nr_class</span></span><span style="">得到。序列是</span><span style=""><span style="font-family: Times New Roman;">label[0] vs. label[1], …, label[0] vs. label[nr_class – 1], label[1] vs. label[2], …, label[nr_class-2] vs. label[nar_class-1], </span></span><span style="">其中</span><span style=""><span style="font-family: Times New Roman;">label</span></span><span style="">可以通过函数</span><span style=""><span style="font-family: Times New Roman;">svm_get_lables</span></span><span style="">得到。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">回归模型中,label[0]表示使用该模型计算所得的</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">函数值。</span><span style=""><span style="font-family: Times New Roman;">one-class</span></span><span style="">模型中,</span><span style=""><span style="font-family: Times New Roman;">label[0]</span></span><span style="">是</span><span style=""><span style="font-family: Times New Roman;">+1</span></span><span style="">或</span><span style=""><span style="font-family: Times New Roman;">-1</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">double svm_predict_probability(const struct svm_model *model,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span><span style=""> </span></span><span style="">const struct svm_node *x, double* prob_estimates);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style=""><span style="font-size: small; font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">在给定带概率信息的模型的前提下,这个函数可以用来对测试向量</span><span style=""><span style="font-family: Times New Roman;">x</span></span><span style="">进行分类或回归。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">对于带有概率信息的分类模型,这个函数会把</span><span style=""><span style="font-family: Times New Roman;">nr_class</span></span><span style="">概率期望输出到数组</span><span style=""><span style="font-family: Times New Roman;">prob_estimates</span></span><span style="">中。</span><span style=""><span style="font-family: Times New Roman;"> nr_class</span></span><span style="">可以通过函数</span><span style=""><span style="font-family: Times New Roman;">svm_get_nr_class</span></span><span style="">得到。返回值是概率值最高的类。对于回归或</span><span style=""><span style="font-family: Times New Roman;">one-class</span></span><span style="">支持向量机,数组</span><span style=""><span style="font-family: Times New Roman;">prob_estimates</span></span><span style="">保持不变,而返回值与</span><span style=""><span style="font-family: Times New Roman;">svm_predict</span></span><span style="">的返回值相同。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">const char *svm_check_parameter(const struct svm_problem *prob,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small; font-family: Times New Roman;">const struct svm_parameter *param);</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">本函数检验对于当前问题,参数是否合法。在调用</span><span style=""><span style="font-family: Times New Roman;">svm_train()</span></span><span style="">和</span><span style=""><span style="font-family: Times New Roman;">svm_cross_validation()</span></span><span style="">之前应该调用此函数。如果参数合法,则返回</span><span style=""><span style="font-family: Times New Roman;">NULL</span></span><span style="">,如果不合法,则返回错误信息。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">int svm_check_probability_model(const struct svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">此函数用于判断当前模型是否含有进行概率期望运算所需要的信息。如果含有则返回</span><span style=""><span style="font-family: Times New Roman;">+1</span></span><span style="">。否则返回</span><span style=""><span style="font-family: Times New Roman;">0</span></span><span style="">。在调用</span><span style=""><span style="font-family: Times New Roman;">sv svm_get_svr_probability</span></span><span style="">和</span><span style=""><span style="font-family: Times New Roman;">svm_predict_probability</span></span><span style="">之前应该调用此函数。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">int svm_save_model(const char *model_file_name,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span lang="EN-US"><span style=""> </span><span style=""> </span></span><span style="">const struct svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="">此函数用于将训练好的模型保存到文件中,如果保存成功则返回</span><span style=""><span style="font-family: Times New Roman;">0</span></span><span style="">,如果发生错误则返回</span><span style=""><span style="font-family: Times New Roman;">-1</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">struct svm_model *svm_load_model(const char *model_file_name);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">此函数从文件中读取模型并返回指向该模型的指针,如果读取失败则回返空指针。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">void svm_destroy_model(struct svm_model *model);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">此函数用于释放指定模型的内存。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style=""><span style="font-family: Times New Roman;">-</span></span><span style="">函数:</span><span style=""><span style="font-family: Times New Roman;">void svm_destroy_param(struct svm_parameter *param);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">此函数用于释放指定参数集的内存。</span></span></p>

你可能感兴趣的:(lib)