matlab练习程序(正态分布贝叶斯分类)
阅读原文时间:2023年07月08日阅读:1

clear all;
close all;
clc;

randn('seed',0);
mu1=[0 0];
S1=[0.3 0;0 0.35];
cls1_data=mvnrnd(mu1,S1,1000);
plot(cls1_data(:,1),cls1_data(:,2),'+');
hold on;

mu2=[4 0];
S2=[1.2 0;0 1.85];
cls2_data=mvnrnd(mu2,S2,1000);
plot(cls2_data(:,1),cls2_data(:,2),'r+');
axis([-8 8 -8 8]);

for i=-4:0.1:8
for j=-6:0.1:6
d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
d=d1-d2;
if d<0.1
plot(i,j);
end

end
end
grid on;

figure;
mu1=[0 0];
S1=[0.1 0;0 0.75];
cls1_data=mvnrnd(mu1,S1,1000);
plot(cls1_data(:,1),cls1_data(:,2),'+');
hold on;

mu2=[3.2 0];
S2=[0.75 0;0 0.1];
cls2_data=mvnrnd(mu2,S2,1000);
plot(cls2_data(:,1),cls2_data(:,2),'r+');
axis([-8 8 -8 8]);

for i=-8:0.1:8
for j=-8:0.1:8
d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
d=d1-d2;
if d<0.1
plot(i,j);
end

end
end
grid on;

figure;
mu1=[0 3];
S1=[0.3 0;0 0.35];
cls1_data=mvnrnd(mu1,S1,1000);
plot(cls1_data(:,1),cls1_data(:,2),'+');
hold on;

mu2=[4 0];
S2=[0.3 0;0 0.35];
cls2_data=mvnrnd(mu2,S2,1000);
plot(cls2_data(:,1),cls2_data(:,2),'r+');

axis([-8 8 -8 8]);

for i=-8:0.1:8
for j=-8:0.1:8
d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
d=d1-d2;
if d<0.1
plot(i,j);
end

end
end
grid on;

figure;
mu1=[0 -3];
S1=[0.5 1;1 2.5];
cls1_data=mvnrnd(mu1,S1,1000);
plot(cls1_data(:,1),cls1_data(:,2),'+');
hold on;

mu2=[4 0];
S2=[0.5 1;1 2.5];
cls2_data=mvnrnd(mu2,S2,1000);
plot(cls2_data(:,1),cls2_data(:,2),'r+');

axis([-8 8 -8 8]);

for i=-8:0.1:8
for j=-8:0.1:8
d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
d=d1-d2;
if d<0.1
plot(i,j);
end

end
end
grid on;

http://www.cnblogs.com/tiandsp/category/348031.html

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章