SVM学习笔记(2 )libsvm--svmtrain\svmpredict函数说明

本文详细介绍了如何使用SVM算法对训练集进行模型训练,并对测试集进行预测的过程。包括了SVM函数参数设置及解释,以及如何评估预测模型的准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

svmtrain(… );

%通过训练集来训练模型

svmpredict( … );

%对测试集进行预测

 

>>model = svmtrain(train_label,train_matrix, ['libsvm_options']);

-train_label:

           An m by 1 vector of training labels (type must be double).

-train_matrix:

           An m by n matrix of m training instances with n features.

           It can be dense or sparse (type must be double).

-libsvm_options:

           A string of training options in the same format as that ofLIBSVM.

===============

The 'svmtrain' functionreturns a model which can be used for future prediction. 

 >> [predicted_label,accuracy, decision_values/prob_estimates] = svmpredict(test_label, test_matrix,model, ['libsvm_options']);

 -test_label:

           An m by 1 vector of prediction labels. If labels of test  dataare unknown, simply use any random values. (type must be double)

-testmatrix:

           An m by n matrix of m testing instances with n features.  It can be dense or sparse. (type must be double)

-model:

           The output of svmtrain.

-libsvm_options:

           A string of testing options in the same format as that ofLIBSVM.

===============

English:

libsvm_options:

-s svm_type : set type of SVM(default 0)

0 -- C-SVC

1 -- nu-SVC

2 -- one-class SVM

3 -- epsilon-SVR

4 -- nu-SVR

-t kernel_type : set type ofkernel function (default 2)

0 -- linear: u'*v

1 -- polynomial: (gamma*u'*v + coef0)^degree

2 -- radial basis function: exp(-gamma*|u-v|^2)

3 -- sigmoid: tanh(gamma*u'*v + coef0)

4 -- precomputed kernel (kernel values in training_instance_matrix)

-d degree : set degree inkernel function (default 3)

-g gamma : set gamma in kernelfunction (default 1/k)

-r coef0 : set coef0 in kernelfunction (default 0)

-c cost : set the parameter Cof C-SVC, epsilon-SVR, and nu-SVR (default 1)

-n nu : set the parameter nuof nu-SVC, one-class SVM, and nu-SVR (default 0.5)

-p epsilon : set the epsilonin loss function of epsilon-SVR (default 0.1)

-m cachesize : set cachememory size in MB (default 100)

-e epsilon : set tolerance oftermination criterion (default 0.001)

-h shrinking: whether to usethe shrinking heuristics, 0 or 1 (default 1)

-b probability_estimates:whether to train a SVC or SVR model for probability estimates, 0 or 1 (default0)

-wi weight: set the parameterC of class i to weight*C, for C-SVC (default 1)

-v n: n-fold cross validationmode

==========================================================

Chinese:

Options:可用的选项即表示的涵义如下

-s svm类型:SVM设置类型(默认0)

  0 -- C-SVC

  1 --nu-SVC

  2 – 一类SVM

  3 -- e -SVR

  4 -- nu-SVR

-t 核函数类型:核函数设置类型(默认2)

  0 – 线性:u'v

  1 – 多项式:(r*u'v + coef0)^degree

  2 – RBF函数:exp(-r|u-v|^2)

  3 –sigmoid:tanh(r*u'v + coef0)

  -d degree:核函数中的degree设置(针对多项式核函数)(默认3)

  -g r(gama):核函数中的gamma函数设置(针对多项式/rbf/sigmoid核函数)(默认1/ k)

  -r coef0:核函数中的coef0设置(针对多项式/sigmoid核函数)((默认0)

  -c cost:设置C-SVC,e -SVR和v-SVR的参数(损失函数)(默认1)

  -n nu:设置nu-SVC,一类SVM和nu- SVR的参数(默认0.5)

  -p p:设置e -SVR 中损失函数p的值(默认0.1)

  -m cachesize:设置cache内存大小,以MB为单位(默认40)

  -e eps:设置允许的终止判据(默认0.001)

  -h shrinking:是否使用启发式,0或1(默认1)

  -wi weight:设置第几类的参数C为weight?C(C-SVC中的C)(默认1)

  -v n: n-fold交互检验模式,n为fold的个数,必须大于等于2

  其中-g选项中的k是指输入数据中的属性数。option -v 随机地将数据剖分为n部分并计算交互检验准确度和均方根误差。以上这些参数设置可以按照SVM的类型和核函数所支持的参数进行任意组合,如果设置的参数在函数或SVM类型中没有也不会产生影响,程序不会接受该参数;如果应有的参数设置不正确,参数将采用默认值。

### 解决PyCharm无法加载Conda虚拟环境的方法 #### 配置设置 为了使 PyCharm 能够成功识别并使用 Conda 创建的虚拟环境,需确保 Anaconda 的路径已正确添加至系统的环境变量中[^1]。这一步骤至关重要,因为只有当 Python 解释器及其关联工具被加入 PATH 后,IDE 才能顺利找到它们。 对于 Windows 用户而言,在安装 Anaconda 时,默认情况下会询问是否将它添加到系统路径里;如果当时选择了否,则现在应该手动完成此操作。具体做法是在“高级系统设置”的“环境变量”选项内编辑 `Path` 变量,追加 Anaconda 安装目录下的 Scripts 文件夹位置。 另外,建议每次新建项目前都通过命令行先激活目标 conda env: ```bash conda activate myenvname ``` 接着再启动 IDE 进入工作区,这样有助于减少兼容性方面的问题发生概率。 #### 常见错误及修复方法 ##### 错误一:未发现任何解释器 症状表现为打开 PyCharm 新建工程向导页面找不到由 Conda 构建出来的 interpreter 列表项。此时应前往 Preferences/Settings -> Project:...->Python Interpreter 下方点击齿轮图标选择 Add...按钮来指定自定义的位置。按照提示浏览定位到对应版本 python.exe 的绝对地址即可解决问题。 ##### 错误二:权限不足导致 DLL 加载失败 有时即使指定了正确的解释器路径,仍可能遇到由于缺乏适当的操作系统级许可而引发的功能缺失现象。特别是涉及到调用某些特定类型的动态链接库 (Dynamic Link Library, .dll) 时尤为明显。因此拥有管理员身份执行相关动作显得尤为重要——无论是从终端还是图形界面触发创建新 venv 流程均如此处理能够有效规避此类隐患。 ##### 错误三:网络连接异常引起依赖下载超时 部分开发者反馈过因网速慢或者其他因素造成 pip install 操作中途断开进而影响整个项目的初始化进度条卡住的情况。对此可尝试调整镜像源加速获取速度或是离线模式预先准备好所需资源包后再继续后续步骤。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值