How to plot two 1-dimensional Gaussian distributions together with the classification boundary [Matlab]?

StackOverflow https://stackoverflow.com/questions/16124935

سؤال

I have two classes(normally distributed), C1 and C2, each defined by their mean and standard deviation. I want to be able to visualize the pdf plot of a normal distributions and the classification boundary between the two. Currently I have the code to plot the distributions but I'm not sure how to go about plotting the decision boundary. Any ideas would be appreciated. I have included a sample of what I want to plot. 1

Many thanks!

هل كانت مفيدة؟

المحلول

This is what I came up with:

% Generate some example data
mu1 = -0.5; sigma1 = 0.7; mu2 = 0.8; sigma2 = 0.5;
x = linspace(-8, 8, 500);
y1 = normpdf(x, mu1, sigma1);
y2 = normpdf(x, mu2, sigma2);

% Plot it
figure; plot(x, [y1; y2])
hold on

% Detect intersection between curves; choose threshold so you get the whole 
% intersection (0.0001 should do unless your sigmas are very large)
ind = y1 .* y2 > 0.0001;
% Find the minimum values in range
minVals = min([y1(ind); y2(ind)]);

if ~isempty(minVals)
    area(x(ind), minVals)
end

I don't know if this is the best way to do what you want, but it seems to work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top