新聞中心
本文小編為大家詳細(xì)介紹“如何使用svmtrain進(jìn)行數(shù)據(jù)分類預(yù)測”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“如何使用svmtrain進(jìn)行數(shù)據(jù)分類預(yù)測”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。
在成都做網(wǎng)站、網(wǎng)站設(shè)計、外貿(mào)營銷網(wǎng)站建設(shè)過程中,需要針對客戶的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計方向。成都創(chuàng)新互聯(lián)公司還需要根據(jù)客戶的需求進(jìn)行功能模塊的開發(fā)和設(shè)計,包括內(nèi)容管理、前臺展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計和安全保護(hù)等功能。
在安裝了libsvm工具箱之后,使用svmtrain進(jìn)行數(shù)據(jù)分類預(yù)測
%% 清空環(huán)境變量
close all;
clear;
clc;
format compact;
%% 數(shù)據(jù)提取
% 載入測試數(shù)據(jù)wine
% 包含的數(shù)據(jù)為classnumber = 3
% wine: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(3,5,1);
hold on
for run = 1:178
plot(run,wine_labels(run),'*');
end
xlabel('樣本','FontSize',10);
ylabel('類別標(biāo)簽','FontSize',10);
title('class','FontSize',10);
for run = 2:14
subplot(3,5,run);
hold on;
str = ['attrib ',num2str(run-1)];
for i = 1:178
plot(i,wine(i,run-1),'*');
end
xlabel('樣本','FontSize',10);
ylabel('屬性值','FontSize',10);
title(str,'FontSize',10);
end
%% 選定訓(xùn)練集和測試集
% 將第一類的1-30,第二類的60-95,第三類的131-153做為訓(xùn)練集
train_wine = [wine(1:30,:);wine(60:95,:);wine(131:153,:)];
% 相應(yīng)的訓(xùn)練集的標(biāo)簽也要分離出來
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,:)];
% 相應(yīng)的測試集的標(biāo)簽也要分離出來
test_wine_labels = [wine_labels(31:59);wine_labels(96:130);wine_labels(154:178)];
%% 數(shù)據(jù)預(yù)處理
% 數(shù)據(jù)預(yù)處理,將訓(xùn)練集和測試集歸一化到[0,1]區(qū)間
[mtrain,ntrain] = size(train_wine);
[mtest,ntest] = size(test_wine);
dataset = [train_wine;test_wine];
% mapminmax為MATLAB自帶的歸一化函數(shù)
[dataset_scale,ps] = mapminmax(dataset',0,1);
dataset_scale = dataset_scale';
train_wine = dataset_scale(1:mtrain,:);
test_wine = dataset_scale( (mtrain+1):(mtrain+mtest),: );
%% SVM網(wǎng)絡(luò)訓(xùn)練
model = svmtrain(train_wine_labels, train_wine, '-c 2 -g 1');
%% SVM網(wǎng)絡(luò)預(yù)測
[predict_label, accuracy] = svmpredict(test_wine_labels, test_wine, model);
%% 結(jié)果分析
% 測試集的實際分類和預(yù)測分類圖
% 通過圖可以看出只有一個測試樣本是被錯分的
figure;

hold on;
plot(test_wine_labels,'o');
plot(predict_label,'r*');
xlabel('測試集樣本','FontSize',12);
ylabel('類別標(biāo)簽','FontSize',12);
legend('實際測試集分類','預(yù)測測試集分類');
title('測試集的實際分類和預(yù)測分類圖','FontSize',12);
grid on;
讀到這里,這篇“如何使用svmtrain進(jìn)行數(shù)據(jù)分類預(yù)測”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點(diǎn)還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前標(biāo)題:如何使用svmtrain進(jìn)行數(shù)據(jù)分類預(yù)測
標(biāo)題來源:http://fisionsoft.com.cn/article/pihdoh.html