考虑两个正态(高斯)分布:第一个特征在于μ= 10,σ= 3。第二个特征是μ= 10,σ= 1
答案 0 :(得分:0)
首先计算这两个分布的概率密度函数。您可以使用此代码进行计算,
function f = gauss_distribution(x, mu, s)
p1 = -.5 * ((x - mu)/s) .^ 2;
p2 = (s * sqrt(2*pi));
f = exp(p1) ./ p2;
假设您有两个数据集x1和x2。然后,
f1 = gauss_distribution(x1,10,3);
f2 = gauss_distribution(x2,10,1);
现在可以像这样完成绘图了,
figure;
plot(x1,f1);
hold on;
plot(x2,f2,'r');
xlabel('name of label');
legend('1st dataset', '2nd dataset');
答案 1 :(得分:0)
MATLAB使用makedist
,pdf
和cdf
命令大大简化了许多发行版的此过程。下面的代码和结果图供参考。
pd1 = makedist('Normal',10,3);
pd2 = makedist('Normal',10,1);
X = [0:.01:20]';
% PDF plot
figure, hold on, box on
p(1) = plot(X,pdf(pd1,X),'b-','DisplayName','N(\mu = 10, \sigma = 3)')
p(2) = plot(X,pdf(pd2,X),'k-','DisplayName','N(\mu = 10, \sigma = 1)')
title('Two Normal Distributions (PDFs)')
xlabel('X')
ylabel('PDF')
legend('show')
set(p,'LineWidth',2.2)
% CDF plot
figure, hold on, box on
p(1) = plot(X,cdf(pd1,X),'b-','DisplayName','N(\mu = 10, \sigma = 3)')
p(2) = plot(X,cdf(pd2,X),'k-','DisplayName','N(\mu = 10, \sigma = 1)')
title('Two Normal Distributions (CDFs)')
xlabel('X')
ylabel('CDF')
legend('show','Location','southeast')
set(p,'LineWidth',2.2)