资源简介
lab02.rar
代码片段和文件信息
load ‘iris.csv‘;
training_set = [iris(1:ceil(50*2/3):); iris(51:50 + ceil(50*2/3):); iris(101:100 + ceil(50*2/3):)];%取每类的前2/3作为训练集
test_set = [iris(ceil(50*2/3) + 1:50:); iris(51 + ceil(50*2/3):100:); iris(101 + ceil(50*2/3):150:)];%取每类的后1/3作为测试集
class1 = test_set(:5);%记录类标
test_set(:5) = 0;
rows1 = find(training_set(:5) == 1);
meanValue1 = mean(training_set(rows11:4));
stdValue1 = std(training_set(rows11:4));
rows2 = find(training_set(:5) == 2);
meanValue2 = mean(training_set(rows21:4));
stdValue2 = std(training_set(rows21:4));
rows3 = find(training_set(:5) == 3);
meanValue3 = mean(training_set(rows31:4));
stdValue3 = std(training_set(rows31:4));
pClass1 = size(rows11) / size(training_set1);
pClass2 = size(rows21) / size(training_set1);
pClass3 = size(rows31) / size(training_set1);
for i = 1:size(test_set1)
attribute = zeros(14);
pAttributeClass = zeros(43);
for j = 1:4
attribute(j) = test_set(ij);
pAttributeClass(j1) = 1/(sqrt(2*pi)*stdValue1(j)) * exp(-(attribute(j) - meanValue1(j))^2 / (2*stdValue1(j)^2));
pAttributeClass(j2) = 1/(sqrt(2*pi)*stdValue2(j)) * exp(-(attribute(j) - meanValue2(j))^2 / (2*stdValue2(j)^2));
pAttributeClass(j3) = 1/(sqrt(2*pi)*stdValue3(j)) * exp(-(attribute(j) - meanValue3(j))^2 / (2*stdValue3(j)^2));
end
%各分类,整个属性集的条件概率
pXC1 = 1;
pXC2 = 1;
pXC3 = 1;
for j = 1:4
pXC1 = pXC1 * pAttributeClass(j1);
pXC2 = pXC2 * pAttributeClass(j2);
pXC3 = pXC3 * pAttributeClass(j3);
end
if (max([pXC1*pClass1 pXC2*pClass2 pXC3*pClass3]) == pXC1*pClass1)
test_set(i5) = 1;
fprintf(‘#%d test example: class is 1\n‘i);
elseif (max([pXC1*pClass1 pXC2*pClass2 pXC3*pClass3]) == pXC2*pClass2)
test_set(i5) = 2;
fprintf(‘#%d test example: class is 2\n‘i);
else
test_set(i5) = 3;
fprintf(‘#%d test example: class is 3\n‘i);
end
end
accurateNum = 0;
for i = 1:size(class11)
if (test_set(i5) == class1(i))
accurateNum = accurateNum + 1;
end
end
accuracy = accurateNum / size(class11);
fprintf(‘朴素贝叶斯算法:%f\n‘accuracy);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2708 2010-03-22 14:39 iris.csv
文件 2299 2011-04-14 23:49 Bayes.m
----------- --------- ---------- ----- ----
5007 2
相关资源
- 微博自动评论助手.crx
- Axure高保真原型:移动客户端的设计与
- 200套PPT模版_带有索引.txt
- 飞狐加速器E版.rar
- CNNIC数字证书工具1.2和rootsupd.exe.zip
- rar(9)
- 课程设计.doc
- 20161031133804181.rar
- Vectorcontrolinductionmotor.rar
- bp.rar
- bianma.rar
- CS_recovery_algorithms_OMP_SP_IHT.zip
- 学生选课系统.rar
- PTHCJIEYA密碼.txt
- GodOfHacker-master.zip
- 中华石杉.txt
- ANSYS19.2破解版.zip
- WindowsServer2008R2(X64)MSDN镜像简体中文
- SAP视频教程地址.docx
- 帝国cmspaypal付款插件.rar
- 全国气象站stations.zip
- sklearn说明.txt
- pb.11.5.2506.rar
- 百度网盘地址.txt
- maxwell最全资料附Maxwell2019最新款.txt
- 小甲鱼课件视频全套.txt
- DJKK音乐器.rar
- 获取腾讯真实视频地址.zip
- gcc-g++.txt
- 相关内容地址.txt
评论
共有 条评论