智能算法-SVM (《MATLAB+神经网络43个案例分析》源代码第十二章)学习笔记

SVM (《MATLAB+神经网络43个案例分析》源代码第十二章)学习笔记

SVM工具包(电脑w64):
链接:https://pan.baidu.com/s/1RCSlYGg4sh0ZJ4AGy6QWjg
提取码:1gdf

安装步骤:
首先,将此工具包添加到matlab的路径中(主页-设置路径-添加并包含子文件夹—选中链接中的解压包解压后的文件),并缓冲工具包(主页-预设-常规-更新工具箱路径缓冲)。
学习出处:Y must be a vector or a character array
将matlab工具包中的.exe文件的命名中的 - 去掉,然后运行
修改后的名称:
在这里插入图片描述在这里插入图片描述

当前文件夹放在 安装路径\toolbox\libsvm-3.24\matlab
在命令窗口执行make语句(当前文件夹的位置必须在工具箱的matlab文件夹下,例如:D:\Software\MATLAB2019b\installation\toolbox\libsvm-3.24\matlab)
make编译后的当前文件

在这里插入图片描述
如果出现这个,在make.m中用COMPFLAGS替换所有CFLAGS(快捷键:ctrl+F)
再执行make语句就会出现下面这个:
在这里插入图片描述

测试程序

load heart_scale;
model = svmtrain(heart_scale_label,heart_scale_inst)
[predict_label,accuracy,PPP] = svmpredict(heart_scale_label,heart_scale_inst,model,'b 1');

结果中出现:Accuracy = 86.6667% (234/270) (classification)即是安装成功
适当修改:
在之前的版本的svm中对数据的预测可能只需要三输入两输出,而现在在svm3.2以上的需要变为四输入三输出;
学习出处:https://blog.csdn.net/zhaomengszu/article/details/69055875
将源代码中的所有svmpredict的输出中可以加preb一个变量,在输入中加入‘b 1’,如下:
源代码

[py,mse] = svmpredict(y,x,model);

修改后

[py,mse,preb] = svmpredict(y,x,model,'b 1');

运行结果

*
optimization finished, #iter = 3
nu = 0.990884
obj = -1.981851, rho = -0.009074
nSV = 4, nBSV = 0
Total nSV = 4
Accuracy = 0% (0/1) (classification)
predictlabel =
     1
==该生为男生
.*
optimization finished, #iter = 350
nu = 0.719833
obj = -88.802168, rho = 0.058346
nSV = 197, nBSV = 13
Total nSV = 197
Accuracy = 99.5% (199/200) (classification)
Accuracy = 68.5714% (48/70) (classification)
.
WARNING: using -h 0 may be faster
*.*
optimization finished, #iter = 104
nu = 0.224906
obj = -0.675055, rho = 0.698514
nSV = 9, nBSV = 2
Mean squared error = 9.52768e-05 (regression)
Squared correlation coefficient = 0.999184 (regression)
真实数据
testy =
   -1.2100
Usage: [predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
       [predicted_label] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
Parameters:
  model: SVM model structure from svmtrain.
  libsvm_options:
    -b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet
    -q : quiet mode (no outputs)
Returns:
  predicted_label: SVM prediction output vector.
  accuracy: a vector with accuracy, mean squared error, squared correlation coefficient.
  prob_estimates: If selected, probability estimate vector.
预测数据
ptesty =
     []
时间已过 0.175680 秒。
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值