91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 201KB
    文件類型: .rar
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-07-08
  • 語言: Matlab
  • 標簽: matlab??SVM??

資源簡介

利用matlab對SVM算法的參數(shù)進行優(yōu)化,從而更好的提升分類性能

資源截圖

代碼片段和文件信息

%%?Matlab神經(jīng)網(wǎng)絡43個案例分析

%?SVM的參數(shù)優(yōu)化——如何更好的提升分類器的性能
%?by?李洋(faruto)
%?http://www.matlabsky.com
%?Email:faruto@163.com
%?http://weibo.com/faruto?
%?http://blog.sina.com.cn/faruto
%?2013.01.01
%%?清空環(huán)境變量
function?chapter_GA
close?all;
clear;
clc;
format?compact;
%%?數(shù)據(jù)提取

%?載入測試數(shù)據(jù)wine其中包含的數(shù)據(jù)為classnumber?=?3wine:178*13的矩陣wine_labes:178*1的列向量
load?wine.mat;

%?畫出測試數(shù)據(jù)的box可視化圖
figure;
boxplot(wine‘orientation‘‘horizontal‘‘labels‘categories);
title(‘wine數(shù)據(jù)的box可視化圖‘‘FontSize‘12);
xlabel(‘屬性值‘‘FontSize‘12);
grid?on;

%?畫出測試數(shù)據(jù)的分維可視化圖
figure
subplot(351);
hold?on
for?run?=?1:178
????plot(runwine_labels(run)‘*‘);
end
xlabel(‘樣本‘‘FontSize‘10);
ylabel(‘類別標簽‘‘FontSize‘10);
title(‘class‘‘FontSize‘10);
for?run?=?2:14
????subplot(35run);
????hold?on;
????str?=?[‘a(chǎn)ttrib?‘num2str(run-1)];
????for?i?=?1:178
????????plot(iwine(irun-1)‘*‘);
????end
????xlabel(‘樣本‘‘FontSize‘10);
????ylabel(‘屬性值‘‘FontSize‘10);
????title(str‘FontSize‘10);
end

%?選定訓練集和測試集

%?將第一類的1-30第二類的60-95第三類的131-153做為訓練集
train_wine?=?[wine(1:30:);wine(60:95:);wine(131:153:)];
%?相應的訓練集的標簽也要分離出來
train_wine_labels?=?[wine_labels(1:30);wine_labels(60:95);wine_labels(131:153)];
%?將第一類的31-59第二類的96-130第三類的154-178做為測試集
test_wine?=?[wine(31:59:);wine(96:130:);wine(154:178:)];
%?相應的測試集的標簽也要分離出來
test_wine_labels?=?[wine_labels(31:59);wine_labels(96:130);wine_labels(154:178)];

%%?數(shù)據(jù)預處理
%?數(shù)據(jù)預處理將訓練集和測試集歸一化到[01]區(qū)間

[mtrainntrain]?=?size(train_wine);
[mtestntest]?=?size(test_wine);

dataset?=?[train_wine;test_wine];
%?mapminmax為MATLAB自帶的歸一化函數(shù)
[dataset_scaleps]?=?mapminmax(dataset‘01);
dataset_scale?=?dataset_scale‘;

train_wine?=?dataset_scale(1:mtrain:);
test_wine?=?dataset_scale(?(mtrain+1):(mtrain+mtest):?);
%%?選擇GA最佳的SVM參數(shù)c&g

%?GA的參數(shù)選項初始化
ga_option.maxgen?=?200;
ga_option.sizepop?=?20;?
ga_option.cbound?=?[0100];
ga_option.gbound?=?[0100];
ga_option.v?=?5;
ga_option.ggap?=?0.9;

[bestaccbestcbestg]?=?gaSVMcgForClass(train_wine_labelstrain_winega_option);

%?打印選擇結果
disp(‘打印選擇結果‘);
str?=?sprintf(?‘Best?Cross?Validation?Accuracy?=?%g%%?Best?c?=?%g?Best?g?=?%g‘bestaccbestcbestg);
disp(str);

%%?利用最佳的參數(shù)進行SVM網(wǎng)絡訓練
cmd?=?[‘-c?‘num2str(bestc)‘?-g?‘num2str(bestg)];
model?=?svmtrain(train_wine_labelstrain_winecmd);

%%?SVM網(wǎng)絡預測
[predict_labelaccuracy]?=?svmpredict(test_wine_labelstest_winemodel);

%?打印測試集分類準確率
total?=?length(test_wine_labels);
right?=?sum(predict_label?==?test_wine_labels);
disp(‘打印測試集分類準確率‘);
str?=?sprintf(?‘Accuracy?=?%g%%?(%d/%d)‘a(chǎn)ccuracy(1)righttotal);
disp(str);

%%?結果分析

%?測試集的實際分類和預測分類圖
figure;
hold?on;
plot(test_wine_labels‘o‘);
plot(predict_label‘r*‘);
xlabel(‘測試集樣本‘‘FontSize‘12);
ylabel(‘類別標簽‘‘FontSize‘12);
legend(‘實際測試集分類‘‘預測測試集分類‘);
title(‘測試集的實際分類和預測分類圖‘‘FontSize‘12);
grid?on;
snapnow;

%%?子函數(shù)?gaSVMcgForClass.m
function?[BestCVaccuracyBestcBestgga_option]?=?gaSVMcgForClass(train_labeltrain_dataga_option)
%?gaSVMcgForClass

%
%?by?faruto
%Email:patrick.lee@foxmail.com?QQ:516667408?http://blog.sina.com.cn/faruto?BNU

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????6042??2013-08-18?10:56??chapter_GridSearch.m

?????文件???????8453??2013-08-18?10:57??chapter_PSO.m

?????文件??????20168??2010-01-30?18:38??wine.mat

?????文件??????25844??2013-08-18?10:57??html\chapter_GA.html

?????文件???????3346??2013-08-18?10:57??html\chapter_GA.png

?????文件???????6819??2013-08-18?10:56??html\chapter_GA_01.png

?????文件??????10865??2013-08-18?10:56??html\chapter_GA_02.png

?????文件??????12979??2013-08-18?10:57??html\chapter_GA_03.png

?????文件???????9064??2013-08-18?10:57??html\chapter_GA_04.png

?????文件??????25305??2013-08-18?10:56??html\chapter_GridSearch.html

?????文件???????3346??2013-08-18?10:56??html\chapter_GridSearch.png

?????文件???????6819??2013-08-18?10:56??html\chapter_GridSearch_01.png

?????文件??????10865??2013-08-18?10:56??html\chapter_GridSearch_02.png

?????文件??????12638??2013-08-18?10:56??html\chapter_GridSearch_03.png

?????文件??????16328??2013-08-18?10:56??html\chapter_GridSearch_04.png

?????文件??????21970??2013-08-18?10:56??html\chapter_GridSearch_05.png

?????文件??????15673??2013-08-18?10:56??html\chapter_GridSearch_06.png

?????文件???????9098??2013-08-18?10:56??html\chapter_GridSearch_07.png

?????文件??????32779??2013-08-18?10:58??html\chapter_PSO.html

?????文件???????3330??2013-08-18?10:58??html\chapter_PSO.png

?????文件???????6819??2013-08-18?10:57??html\chapter_PSO_01.png

?????文件??????10865??2013-08-18?10:57??html\chapter_PSO_02.png

?????文件??????13951??2013-08-18?10:58??html\chapter_PSO_03.png

?????文件???????9095??2013-08-18?10:58??html\chapter_PSO_04.png

?????文件???????6450??2013-08-18?10:56??chapter_GA.m

?????目錄??????????0??2017-12-15?10:33??html

-----------?---------??----------?-----??----

???????????????308911????????????????????26


評論

共有 條評論