【SVM分類】基于風(fēng)驅(qū)動(dòng)算法優(yōu)化支持向量機(jī)實(shí)現(xiàn)數(shù)據(jù)分類附matlab代碼
1 簡(jiǎn)介
支持向量機(jī)是利用已知數(shù)據(jù)類別的樣本為訓(xùn)練樣本,尋找同類數(shù)據(jù)的空間聚集特征,從而對(duì)測(cè)試樣本進(jìn)行分類驗(yàn)證,通過(guò)驗(yàn)證可將分類錯(cuò)誤的數(shù)據(jù)進(jìn)行更正。本文以體檢數(shù)據(jù)為數(shù)據(jù)背景,首先通過(guò)利用因子分析將高維數(shù)據(jù)進(jìn)行降維,由此將所有指標(biāo)整合成幾個(gè)綜合性指標(biāo);為降低指標(biāo)之間的衡量標(biāo)準(zhǔn)所引起的誤差,本文利用 MATLAB軟件將數(shù)據(jù)進(jìn)行歸一化處理,結(jié)合聚類分析將數(shù)據(jù)分類;最后本文利用最小二乘支持向量機(jī)分類算法進(jìn)行分類驗(yàn)證,從而計(jì)算出數(shù)據(jù)分類的準(zhǔn)確率,并驗(yàn)證了數(shù)據(jù)分類的準(zhǔn)確性和合理性。


2 部分代碼
%--------------------------------------------------------------
tic; ?
clear; ?
close all; ?
clc; ?
format long g;
delete('WDOoutput.txt'); ?
delete('WDOpressure.txt'); ?
delete('WDOposition.txt');
fid=fopen('WDOoutput.txt','a');
%--------------------------------------------------------------
% User defined WDO parameters:
param.popsize = 20; ? ?% population size.
param.npar = 5; ? ? ?% Dimension of the problem.
param.maxit = 500; ? ?% Maximum number of iterations.
param.RT = 3; ? ? ?% RT coefficient.
param.g = 0.2; ? ? ?% gravitational constant.
param.alp = 0.4; ? ?% constants in the update eq.
param.c = 0.4; ? ? ?% coriolis effect.
maxV = 0.3; ? ? ?% maximum allowed speed.
dimMin = ?-5; ? ? ?% Lower dimension boundary.
dimMax= 5; ? ? ?% Upper dimension boundary.
%---------------------------------------------------------------
% Initialize WDO population, position and velocity:
% Randomize population in the range of [-1, 1]:
pos = 2*(rand(param.popsize,param.npar)-0.5);
% Randomize velocity:
vel = maxV * 2 * (rand(param.popsize,param.npar)-0.5); ?
%---------------------------------------------------------------
% Evaluate initial population: (Sphere Function)
for K=1:param.popsize,
?x = (dimMax - dimMin) * ((pos(K,:)+1)./2) + dimMin;
? ? ?pres(K,:) = sum (x.^2);
end
%----------------------------------------------------------------
% Finding best air parcel in the initial population :
[globalpres,indx] = min(pres);
globalpos = pos(indx,:);
minpres(1) = min(pres); ? ? ?% minimum pressure
%-----------------------------------------------------------------
% Rank the air parcels:
[sorted_pres rank_ind] = sort(pres);
% Sort the air parcels:
pos = pos(rank_ind,:);
keepglob(1) = globalpres;
%-----------------------------------------------------------------
% Start iterations :
iter = 1; ? % iteration counter
for ij = 2:param.maxit,
? ? ?% Update the velocity:
? ? ?for i=1:param.popsize
? ?% choose random dimensions:
? ?a = randperm(param.npar); ? ? ? ? ? ? ?
? ?% choose velocity based on random dimension:
? ? ? ?velot(i,:) = vel(i,a); ? ? ? ?
? ? ? ? ?vel(i,:) = (1-param.alp)*vel(i,:)-(param.g*pos(i,:))+ ...
? ? ? ? ? ?abs(1-1/i)*((globalpos-pos(i,:)).*param.RT)+ ...
? ? ? ? ? ?(param.c*velot(i,:)/i);
? ? ?end
? ? ? ? ?% Check velocity:
? ? ? ? ?vel = min(vel, maxV);
? ? ? ? ?vel = max(vel, -maxV);
? ?% Update air parcel positions:
? ? ? ?pos = pos + vel;
? ? ? ? ?pos = min(pos, 1.0);
? ? ? ? ?pos = max(pos, -1.0);
? ?% Evaluate population: (Pressure)
? ?for K=1:param.popsize,
? ? ?x = (dimMax - dimMin) * ((pos(K,:)+1)./2) + dimMin;
? ? ? ? ?pres(K,:) = sum (x.^2);
? ?end
? ? ?%----------------------------------------------------
? ? ?% Finding best particle in population
? ? ?[minpres,indx] = min(pres);
? ? ?minpos = pos(indx,:); ? ? ? ? ? ? % min location for this iteration
? ? ?%----------------------------------------------------
? ? ?% Rank the air parcels:
? ? ?[sorted_pres rank_ind] = sort(pres);
? ? ?% Sort the air parcels position, velocity and pressure:
? ? ?pos = pos(rank_ind,:);
? ? ?vel = vel(rank_ind,:);
? ? ?pres = sorted_pres; ?
? ? ?% Updating the global best:
? ? ?better = minpres < globalpres;
? ? ?if better
? ? ? ? ? ?globalpres = minpres ? ? ? ? ? ? % initialize global minimum
? ? ? ? ? ?globalpos = minpos;
? ? end
?% Keep a record of the progress:
? ? ?keepglob(ij) = globalpres;
? ? ?save WDOposition.txt pos -ascii -tabs;
end
?%Save values to the final file.
? ? ?pressure = transpose(keepglob);
? ? ?save WDOpressure.txt pressure -ascii -tabs;
? ? ?%END
%-----------------------------------------------------
3 運(yùn)行結(jié)果

4 參考文獻(xiàn)
[1]張燁, 黃偉. 基于天牛群算法優(yōu)化SVM的磨煤機(jī)故障診斷.?
博主簡(jiǎn)介:擅長(zhǎng)智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測(cè)、信號(hào)處理、元胞自動(dòng)機(jī)、圖像處理、路徑規(guī)劃、無(wú)人機(jī)等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問(wèn)題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。
