当前位置: 首页 > ds >正文

MNIST数据集上朴素贝叶斯分类器(MATLAB)

MNIST数据集上朴素贝叶斯分类器

Naive Bayes Classification

fitcnb
Train multiclass naive Bayes model
Syntax
Mdl = fitcnb(Tbl,ResponseVarName)
Mdl = fitcnb(Tbl,formula)
Mdl = fitcnb(Tbl,Y)
Mdl = fitcnb(X,Y)
Mdl = fitcnb(___,Name,Value)
[Mdl,AggregateOptimizationResults] = fitcnb(___)

Normal (Gaussian) Distribution
The ‘normal’ distribution (specify using ‘normal’ ) is appropriate for predictors that have normal distributions in each class. For each predictor you model with a normal distribution, the naive Bayes classifier estimates a separate normal distribution for each class by computing the mean and standard deviation of the training data in that class.

Kernel Distribution
The ‘kernel’ distribution (specify using ‘kernel’) is appropriate for predictors that have a continuous distribution. It does not require a strong assumption such as a normal distribution and you can use it in cases where the distribution of a predictor may be skewed or have multiple peaks or modes. It requires more computing time and more memory than the normal distribution. For each predictor you model with a kernel distribution, the naive Bayes classifier computes a separate kernel density estimate for each class based on the training data for that class. By default the kernel is the normal kernel, and the classifier selects a width automatically for each class and predictor. The software supports specifying different kernels for each predictor, and different widths for each predictor or class.

DistributionNames — fitcnb searches among 'normal' and 'kernel'.
Kernel — fitcnb searches among 'normal', 'box', 'epanechnikov', and 'triangle'.

使用pca作为降维,pca是一种非监督的线性降维方法。方差贡献率作为参数。


10000个样本的样本集

Label    Count
_____    _____0      1000 1      1000 2      1000 3      1000 4      1000 5      1000 6      1000 7      1000 8      1000 9      1000 

在这里插入图片描述


%% 
filename = 'mnist';
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...'IncludeSubfolders',true,'LabelSource','foldernames');
%%
labelCount = countEachLabel(imds);
%%
Y = imds.Labels;
for i = 1:sum(labelCount.Count)img = im2double(readimage(imds,i));imgs(:,i) = img(:);
end%% 
[coeff,score,latent,tsquared,explained,mu] = pca(imgs');
% figure;plot(explained)
%% 
idx = explained > 0.05;
X = score(:,idx);%% 
DistributionNames = 'kernel';
Mdl = fitcnb(X,Y,"DistributionNames",DistributionNames);
isLabels = resubPredict(Mdl);

在这里插入图片描述


%% 
filename = 'mnist';
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...'IncludeSubfolders',true,'LabelSource','foldernames');
%%
labelCount = countEachLabel(imds);
%%
Y = imds.Labels;
for i = 1:sum(labelCount.Count)img = im2double(readimage(imds,i));imgs(:,i) = img(:);
end%% 
[coeff,score,latent,tsquared,explained,mu] = pca(imgs');
% figure;plot(explained)
%% 
idx = explained > 0.05;
X = score(:,idx);%% 
DistributionNames = 'normal';
Mdl = fitcnb(X,Y,"DistributionNames",DistributionNames);
isLabels = resubPredict(Mdl);

在这里插入图片描述

http://www.xdnf.cn/news/13470.html

相关文章:

  • 扁平表+递归拼树思想
  • cf2117E
  • 【Pandas】pandas DataFrame interpolate
  • echarts 数据大屏(无UI设计 极简洁版)
  • [2025CVPR]DeepVideo-R1:基于难度感知回归GRPO的视频强化微调框架详解
  • 黄晓军所长:造血干细胞移植后晚期效应及患者健康相关生存质量
  • SQL进阶之旅 Day 23:事务隔离级别与性能优化
  • CentOS 安装Python 3教程
  • 38 C 语言字符串搜索与分割函数详解:strchr、strrchr、strpbrk、strstr、strcspn、strtok
  • 现代汽车在巴黎和得克萨斯州宣传其混合动力汽车为「两全其美之选」
  • CppCon 2015 学习:Extreme Type Safety with Opaque Typedefs
  • 从走线到互连:优化高速信号路径设计的快速指南
  • vue 监听页面滚动
  • carla与ros坐标变换
  • iOS 抖音首页头部滑动标签的实现
  • 【DAY45】 Tensorboard使用介绍
  • 《高等数学》(同济大学·第7版)第三章第五节“函数的极值与最大值最小值“
  • github.com 链接127.0.0.1
  • 征程 6E/M|如何解决量化部署时 mul 与 bool 类型数据交互的问题
  • 《为什么 String 是 final 的?Java 字符串池机制全面解析》
  • MySql简述
  • 基于GeoTools求解GeoTIFF的最大最小值方法
  • 搞了两天的win7批处理脚本问题
  • SaaS(软件即服务)和 PaaS(平台即服务)的定义及区别(服务对象不同、管理责任边界、典型应用场景)
  • GO自带日志库log包解释
  • 【二】12.关于中断
  • APM32芯得 EP.10 | 基于APM32F411控制的一个软开关电路设计分享
  • yolo格式分割标签可视化,coco-seg数据集
  • 6个月Python学习计划 Day 19 - 模块与包的实战拆分
  • 【Java】在 Spring Boot 中集成 Spring Security + JWT 实现基于 Token 的身份认证