⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svm_light.m

📁 一个matlab的工具包,里面包括一些分类器 例如 KNN KMEAN SVM NETLAB 等等有很多.
💻 M
字号:
function  [Y_compute, Y_prob] = SVM_Light(para, X_train, Y_train, X_test, Y_test, num_class)

global temp_model_file SVMLight_dir;

class_set = GetClassSet(Y_train);
if (nargin <= 5), num_class = 2; end;
if (nargin <= 4), Y_test = zeros(size(X_test, 1), 1); end;

if (num_class > 2)
    error('SVM_light: The class number is larger than 2!');
end;

p = str2num(char(ParseParameter(para, {'-Kernel';'-KernelParam'; '-CostFactor'; '-Threshold'}, {'0';'0.05';'1';'0'}, 1)));

% Convert the binary labels into +/-1
Y_train =  (Y_train == class_set(1)) - (Y_train ~= class_set(1));

% Building the model
net = svml(temp_model_file, 'Kernel', p(1), 'KernelParam', p(2), 'CostFactor', p(3), 'ExecPath', SVMLight_dir);
% Learning the parameters
if (~isempty(X_train)),
    net = svmltrain(net, X_train, Y_train);
end;
% Compute prediction on the test data
Ypred = svmlfwd(net, X_test);

threshold = p(4);
Y_compute = class_set(1) * (Ypred >= threshold) + class_set(2) * (Ypred < threshold);
% Y_prob = (1 ./ (1 + exp(-Ypred))) .* (Ypred >= threshold) + (1 ./ ( 1 + exp(Ypred) )) .* (Ypred < threshold) ;
Y_prob = 1 ./ (1 + exp(-Ypred));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -