📄 build_classifier.m
字号:
function [CA,SV,b]=Build_classifier(Z_train, C_train,value_lambda,value_gamma)
% ____________________ INPUTS ____________________:
% Z_train is a matrix of training data, with "N_train" ROWs and "D" COLUMNs
% i^{th} ROW of Z_train is the i^{th} training point
% N_train ---- the number of training data
% D ---- the dimension of the training data
% C_train is a COLUMN vector, with length "N_train"
% C_train(i) is the class label of i^{th} training point
% C_train(i) = either 1 or -1 !!!!!!
% value_lambda is a positive scalar = the value of slack penalty (lambda).
% value_gamma is a positive scalar = the value of gamma in RBF kernel,
% K(u, v) = exp(-gamma * ( || u-v||^2 ) ).
% _______________________ OUTPUTS ____________________:
% SV is a matrix of support vectors, with "N_SV" rows and "D" columns
% i^{th} row of SV (denoted by sv_i) is the i^{th} support vector
% N_SV ------ the number of support vectors
% D ---- defined as above.
%
% CA is a column vector, with length "N_SV"
% i^{th} element of CA = (c_i * alpha_i)
% c_i ----- the original class label of sv_i
% alpha_i ----- the positive weight associated with sv_i
% b is a scalar = the constant term in the definition of the classifier H(z)
% ____________________ How to Use the Outputs ( CA, SV and b ) _______:
% The SVM classifier H(z) associated with Z_train, C_train, value_lambda
% and RBF kernel( with parameter value_gamma) is :
% H(z) = sign { [\sum_{i=1}^{N_SV} c_i * alpha_i * K(sv_i, z) ] + b }
% = sign { [\sum_{i=1}^{N_SV} CA(i) * K(sv_i, z) ] + b }
% ( where
% N_SV = number of rows of SV
% CA(i) is the i^{th} element of CA
% sv_i is the i^{th} row of SV, i.e the i^{th} support vector
% K(sv_i, z) = exp( - value_gamma * ( || sv_i - z ||^2 ) )
% ).
fname_train='train.txt';
fname_model='model.txt';
D=size(Z_train,2);
write_data_into_txt(Z_train,C_train,fname_train);
write_cmd(value_lambda, value_gamma, fname_train, fname_model);
svm_cmd;
[CA,SV,b]=readin_model(fname_model,D);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -