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

  • 相关阅读:
    NSURL 的简单实用
    动画demo
    UIScrollView的简单页面
    关于UITableview(更新)
    添加手势
    多线程
    IOS 瀑布流
    高低字节序转换(htonl、ntohl、htons、ntohs函数)
    Xcode个版本
    网址
  • 原文地址:https://www.cnblogs.com/Kermit-Li/p/4023238.html
Copyright © 2011-2022 走看看