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;

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

  • 相关阅读:
    js语言基础练习(二)---------------函数的基础知识
    js语言基础练习
    js基本语法总结(一)
    HTML基础知识总结
    参考资料
    css基础知识的复习总结(三)
    css基础知识的复习总结(二)
    css基础知识的复习总结
    旋转数组
    CSS 之 position
  • 原文地址:https://www.cnblogs.com/Kermit-Li/p/4023238.html
Copyright © 2011-2022 走看看