资源简介

最简单的贝叶斯分类器演示Matlab程序。入门必备。 详细请参考本人的博客http://blog.csdn.net/ranchlai/article/details/10375579

资源截图

代码片段和文件信息

%
% Liscense Notification 2013
%
% Redistributions in source and binary forms with or without
% modification are totally FREE provided that you keep this keep this
% notification
%
%  Descritption: This package demonstrates the discrete adaboost with
%  stump(decision tree with only the root node) weak classifers.
%  Author:  Ranch Lai (ranchlai@hotmail.com)
%  Release date: Aug 17 2013
%/
%%
clc;
clear;
close all;


%% generate random data
shift =3.0;
n = 2;%2 dim
%y = 1./exp(-w‘*x+b)
sigma = 1;
N = 500;
x = [randn(nN/2)-shift randn(nN/2)*sigma+shift];
y = [ones(N/21);-ones(N/21)];

%show the data
figure;
plot(x(11:N/2)x(21:N/2)‘rs‘);
hold on;
plot(x(11+N/2:N)x(21+N/2:N)‘go‘);
title(‘2d training data‘);
legend(‘Positve samples‘‘Negative samples‘‘Location‘‘SouthEast‘);

% model fitting using maximum likelihood
[model_posmodel_neg] = FindGuassianModel(xy);

%% test on new dataset same distribution

n = 2;%2 dim
%y = 1./exp(-w‘*x+b)
sigma = 2;
N = 500;
x = [randn(nN/2)-shift randn(nN/2)*sigma+shift];
y = [ones(N/21);-ones(N/21)];

figure;
plot(x(11:N/2)x(21:N/2)‘rs‘);
hold on;
plot(x(11+N/2:N)x(21+N/2:N)‘go‘);
title(‘2d testing data‘);
hold on;

%% gaussian model as a baseline
[errh] = FindModelError(model_posmodel_negxy);
fprintf(‘Baysian error on test data set: %f\n‘err/N);
x_pos = x(:h==1);
x_neg = x(:h~=1);
plot(x_pos(1:)x_pos(2:)‘r.‘);
hold on;
plot(x_neg(1:)x_neg(2:)‘g.‘);
legend(‘Positve samples‘‘Negative samples‘‘Positve samples as predicted‘‘Negative samples as predicted‘‘Location‘‘SouthEast‘);


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-08-27 03:07  Baysian+Gaussian\
     文件        8669  2013-08-27 03:07  Baysian+Gaussian\training.png
     文件       11809  2013-08-27 03:07  Baysian+Gaussian\predict.png
     文件        1583  2013-08-27 03:04  Baysian+Gaussian\demo_adaboost.m
     文件         615  2013-08-26 09:43  Baysian+Gaussian\FindModelError.m
     文件         401  2013-08-26 10:01  Baysian+Gaussian\FindGuassianModel.m

评论

共有 条评论