【MATLAB第58期】基于MATLAB的PCA-Kmeans、PCA-LVQ与BP神经网络分类预测模型对比

【MATLAB第58期】基于MATLAB的PCA-Kmeans、PCA-LVQ与BP神经网络分类预测模型对比

一、数据介绍

基于UCI葡萄酒数据集进行葡萄酒分类及产地预测

共包含178组样本数据,来源于三个葡萄酒产地,每组数据包含产地标签及13种化学元素含量,即已知类别标签。

把样本集随机分为训练集和测试集(70%训练,30%测试),根据已有数据集训练一个能进行葡萄酒产地预测的模型,以正确区分三个产地所产出的葡萄酒,

分别采用PCA+Kmeans、PCA+LVQ、BP神经网络等方法进行模型的训练与测试,准确率都能达到95%左右。

二、效果展示

1.PCA-Kmeans




train_accuracy = 0.95

test_accuracy = 0.98

2.PCA-LVQ




3.BP


三、代码展示(部分代码)

bash 复制代码
clear all;
wine_data = xlsread('wine.xlsx');  %分类标签默认第一列

method = 'BP';%PK: PCA & Kmeans 
%PL:        PCA & LVQ  
%BP:         BP Neural Network'
rate = 0.7;%训练集70%,测试集30%
N = size(unique(wine_data(:,1)),1);;

total_cnt = size(wine_data,1);
train_cnt = round(total_cnt*rate);
test_cnt = total_cnt - train_cnt;

rand_idx = randperm(total_cnt);
train_idx = rand_idx(1:train_cnt);
test_idx = rand_idx(train_cnt+1:total_cnt);

train_data = wine_data(train_idx,2:size(wine_data,2));
train_class = wine_data(train_idx,1);
test_data = wine_data(test_idx,2:size(wine_data,2));
test_class = wine_data(test_idx,1);
dim = size(wine_data,2)-1;

%矩阵z-score标准化
train_SM = zeros(train_cnt,dim);
data_mean = mean(train_data);
data_std = std(train_data);
test_SM = zeros(test_cnt,dim);
for j = 1:dim
    train_SM(:,j) = (train_data(:,j) - data_mean(j)) / data_std(j);
    test_SM(:,j) = (test_data(:,j) - data_mean(j)) / data_std(j);
end

四、代码获取

私信回复"58期"即可获取下载链接。

相关推荐
狂奔solar2 天前
PCA主成分分析 —— 用更少的维度保留最多的信息
机器学习·pca
AI即插即用2 天前
即插即用系列 | IEEE TMI PLG-HN:原型学习引导的 CNN-Transformer 混合网络,攻克乳腺肿瘤分割难题
人工智能·深度学习·神经网络·学习·目标检测·cnn·transformer
机器学习之心2 天前
基于CEEMDAN-TCN-BiGRU的空气质量指数(AQI)预测研究,五模型对比,实验报告+MATLAB代码
matlab·tcn-bigru·ceemdan·空气质量指数
是上好佳佳佳呀2 天前
【深度学习|DAY03】神经网络深度学习笔记(上):框架总览、参数初始化与激活函数
笔记·深度学习·神经网络
牧羊人.3333 天前
速通机器学习 11| K-Means 聚类
机器学习·kmeans·聚类
吃好睡好便好3 天前
MATLAB仿真框图3
开发语言·matlab·仿真·simulink
吃好睡好便好4 天前
MATLAB仿真框图2
开发语言·matlab·仿真·simulink
hhzz4 天前
《深度学习框架PyTorch入门与实践》系列:04-nn模块详解:用积木搭建神经网络
pytorch·深度学习·神经网络
LaughingZhu4 天前
Product Hunt 每日热榜 | 2026-08-09
人工智能·深度学习·神经网络·搜索引擎·百度
AI街潜水的八角4 天前
水上垃圾检测和识别2:基于深度学习YOLO26神经网络实现水上垃圾检测和识别(含训练代码和数据集)
人工智能·深度学习·神经网络