zoukankan      html  css  js  c++  java
  • matlab练习程序(正态分布贝叶斯分类)

    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;

    图片福利:

    参考:

    1.Sergios Theodoridis and Konstantinos Koutroumbas."Pattern Recognition"(Fourth Edition).2009.13-23.

  • 相关阅读:
    随机数生成器
    赌博的艺术
    基本算法——包罗万象
    对于搜索的新理解
    关于动态规格的新理解
    发现的好东西——bitset
    高精度(重定义版)——来自
    ac自动机(模板)
    数据采集框架Gobblin简介
    Hadoop的数据采集框架
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2508384.html
Copyright © 2011-2022 走看看