function [predictive, posterior] = predict_nbc(test, priors, likelihood)
%PREDICT_NBC uses a naive bayes classifier to predict the class labels of
%the test data set.
%% [predictive, posterior] = predict_nbc(test, priors, likelihood)
%% Input:
% test - a struct representing the test data set
% test.class - the class of each data
% test.features - the feature of each data
% priors - a struct representing the priors of each class
% priors.class - the class labels
% priors.value - the priors of its corresponding classes
% likelihood - a struct representing the likelihood
% likelihood.matrixColnames - the feature values
% likelihood.matrixRownames - the class labels
% likelihood.matrix - the likelihood values
%% Output:
% predictive - the predictive results of the test data set
% predictive.class - the predictive class for each data
% posterior - a struct representing the posteriors of each class
% posterior.class - the class labels
% posterior.value - the posteriora of the corresponding classes
%% Running these code to get some examples:
%nbc_mushroom
%% Edited by X. Sun
% My homepage: http://pamixsun.github.io/
%%
% Check the input arguments
if nargin < 3
error(message('MATLAB:UNIQUE:NotEnoughInputs'));
end
posterior.class = priors.class;
% Calculate posteriors for each test data record
predictive.class = zeros(length(size(test.features, 1)), 1);
posterior.value = zeros(size(test.features, 1), length(priors.class));
for i = 1 : size(test.features, 1)
record = test.features(i, :);
% Calculate posteriors for each possible class of that record
for j = 1 : length(priors.class)
class = priors.class(j);
% Initialize posterior as the prior value of that class
posteriorValue = priors.value(priors.class == class);
for k = 1 : length(record)
item = record(k);
likelihoodValue = ...
likelihood.matrix{k}(j, likelihood.matrixColnames{k}(:) == item);
posteriorValue = posteriorValue * likelihoodValue;
end
% Calculate the posteriors
posterior.value(i, j) = posteriorValue;
end
% Get the predictive class
predictive.class(i) = ...
posterior.class(posterior.value(i, :) == max(posterior.value(i, :)));
end
predictive.class = char(predictive.class);
predictive.class = predictive.class(:);
end

云端暮雪
- 粉丝: 176
- 资源: 3
最新资源
- docker-compose安装包,可直接使用,本人亲测
- unity的UI框架,简单好用,已在成熟项目中使用
- 洛阳市乡镇边界,矢量边界,shp格式
- veclibm111111111111
- 平顶山市乡镇边界,矢量边界,shp格式
- 安阳市乡镇边界,矢量边界,shp格式
- docker desk4.32.0
- 2025年中国人工智能计算力发展评估报告
- 基于Springboot汽车销售管理:管理员功能实现,论坛管理,用户管理,汽车管理,汽车评价管理,汽车试驾预定管理,汽车订单管理,用户功能实现,汽车信息,预约汽车试驾,购物车,确认下单,我的汽车订单
- build test yyyy
- 允许在Unity中上传PLY和OFF格式的点云文件
- 基于深度学习的图像修复使用到的模型
- 毕设基于深度学习LSTM、RNN、Transformer模型实现非侵入式负荷检测项目(含源码+详细说明+模型+数据集+实验结果).zip
- 深入解读JVM类加载机制、对象创建与内存管理及相关优化
- 高并发秒杀抢购系统选型与库存管理机制分析
- 久坐提醒,秒表,计算器,便签,快捷方式小工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
- 4
- 5
- 6
前往页