详解例子程序
[heart_scale_label,heart_scale_inst]=libsvmread('heart_scale');
model = svmtrain(heart_scale_label,heart_scale_inst, '-c 1 -g 0.07');
[predict_label,accuracy, dec_values] = svmpredict(heart_scale_label,heart_scale_inst,model);
*heart_scale_label是与heart_scale_inst一一对应的标签,普通n*1维数组就可以表示
例:
1
0
0
1
1
......
*heart_scale_inst是存储所有实例的特征值,二维n*m维数组表示就可以
例:
5.1 3.5 1.4 0.2
4.9 3.0 1.4 0.2
4.7 3.2 1.3 0.2
4.6 3.1 1.5 0.2
5.0 3.6 1.4 0.2
5.4 3.9 1.7 0.4
4.6 3.4 1.4 0.3
5.0 3.4 1.5 0.2 ……
*heart_scale的格式为,第一列是heart_scale,每行紧跟着对应实例的特征值矩阵heart_scale_inst,每个特征值前边都要有相应的标号,一般从1开始标到最后
例:
+1 1:0.708333 2:1 3:1 4:-0.320755 5:-0.105023 6:-1 7:1 8:-0.419847 9:-1 10:-0.225806 12:1 13:-1
-1 1:0.583333 2:-1 3:0.333333 4:-0.603774 5:1 6:-1 7:1 8:0.358779 9:-1 10:-0.483871 12:-1 13:1
+1 1:0.166667 2:1 3:-0.333333 4:-0.433962 5:-0.383562 6:-1 7:-1 8:0.0687023 9:-1 10:-0.903226 11:-1 12:-1 13:1
-1 1:0.458333 2:1 3:1 4:-0.358491 5:-0.374429 6:-1 7:-1 8:-0.480916 9:1 10:-0.935484 12:-0.333333 13:1
-1 1:0.875 2:-1 3:-0.333333 4:-0.509434 5:-0.347032 6:-1 7:1 8:-0.236641 9:1 10:-0.935484 11:-1 12:-0.333333 13:-1
...................
运行结果就保存在predict_label,accuracy, dec_values这三个变量中
predicted_label: SVM 预测输出向量
accuracy: 一个包含准确率,均方差,相关系数的向量
prob_estimates: If selected, probability estimate vector.