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

📄 svm_class_iris.m

📁 模式识别中的十大经典算法,有详细的实现过程,花了很大工夫,现挥泪上传
💻 M
字号:
function result=Svm_Class_Iris()

clear all
clc
load 'D:/iris.mat'

n=1000;
acc_ratio=zeros(1,n);
acc=zeros(1,n);
time=zeros(1,n);

for i=1:1:n
    tic
    
    m=25;
    p1 = randperm(50);
    train_index1 = p1(1,1:m);
    train_data1 = Iris(train_index1,:);
    predict_data1=Iris(setdiff(p1,train_index1),:);

    p3 = randperm(50)+100;
    train_index3=p3(1,1:m);
    train_data3 = Iris(train_index3,:);
    predict_data3=Iris(setdiff(p3,train_index3),:);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    tlabels1=ones(size(train_data1,1),1);
    tlabels3=ones(size(train_data3,1),1)*-1;
    train_label=cat(1,tlabels1,tlabels3);
    train_data=cat(1,train_data1,train_data3);

    plabels1=ones(size(predict_data1,1),1);
    plabels3=ones(size(predict_data3,1),1)*-1;
    predict_label=cat(1,plabels1,plabels3);
    predict_data=cat(1,predict_data1,predict_data3);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %{
    "-s svm_type : set type of SVM (default 0)\n"
	"	0 -- C-SVC\n"
	"	1 -- nu-SVC\n"
	"	2 -- one-class SVM\n"
	"	3 -- epsilon-SVR\n"
	"	4 -- nu-SVR\n"
	"-t kernel_type : set type of kernel function (default 2)\n"
	"	0 -- linear: u'*v\n"
	"	1 -- polynomial: (gamma*u'*v + coef0)^degree\n"
	"	2 -- radial basis function: exp(-gamma*|u-v|^2)\n"
	"	3 -- sigmoid: tanh(gamma*u'*v + coef0)\n"
	"	4 -- precomputed kernel (kernel values in training_instance_matrix)\n"
	"-d degree : set degree in kernel function (default 3)\n"
	"-g gamma : set gamma in kernel function (default 1/k)\n"
	"-r coef0 : set coef0 in kernel function (default 0)\n"
	"-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n"
	"-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n"
	"-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n"
	"-m cachesize : set cache memory size in MB (default 100)\n"
	"-e epsilon : set tolerance of termination criterion (default 0.001)\n"
	"-h shrinking: whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
	"-b probability_estimates: whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n"
	"-wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
	"-v n: n-fold cross validation mode\n"
    %}
    model=svmtrain(train_label,train_data,'-s 1 -t 1');
    [check_label, taccuracy]=svmpredict(train_label,train_data,model);
    [new_label2 , paccuracy]=svmpredict(predict_label,predict_data,model);

    acc(i)=taccuracy(1);
    acc_ratio(i)=paccuracy(1);
    clc;
    
    t=toc;
    time(i)=t;
end
format long
result.train_acc=mean(acc);
result.paccuracy_mean=mean(acc_ratio);
result.paccuracy_var=std(acc_ratio,1,2);
result.exp_itreration=n;
result.train_samples=m;
result.test_samples=50-m;
result.time_mean=mean(time);

⌨️ 快捷键说明

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