Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:36:11+00:00 2026-05-27T02:36:11+00:00

I am trying to visualize the decision boundary when using a Bayesian classifier in

  • 0

I am trying to visualize the decision boundary when using a Bayesian classifier in MATLAB. To do this, I have written an implicit functions which uses training data to determine which of two classes a datapoint P=(x,y) belongs to. This is done be evaluating if the function is positive or negative. The decision boundary corresponds to points where the function is zero.

However, when trying to use this function (stored in a seperate .m file), ezplot fail to draw any lines and instead issues the warning:
Warning: Contour not rendered for constant ZData

In contour>parseargs at 204
  In contour at 72
  In ezplot>ezimplicit at 312
  In ezplot at 155

I’ve made some sample code so that the problem can be recreated:

%Create synthetic dataset. Bivariate gaussian mixture
p1 = 0.7;
p2 = 1 - p1;

%Number of datapoints
N = 50;

%Means
mu1 = [0; 0];
mu2 = [2.5; 2.5];

%Covariance
Sigma = eye(2);

%Loss matrix
L = [0 1; 1 0];

%Create data, 2 classes
D1 = mvnrnd(mu1, Sigma, round(N*p1));
D2 = mvnrnd(mu2, Sigma, round(N*p2));

% Visualize decision boundary using kNN classifier
f2=figure(2);
plot(D1(:,1),D1(:,2),'b.',D2(:,1),D2(:,2),'r.');
hold on;

k=5;
ezp=ezplot(@(x,y) kNNdbEval(x,y,D1,D2,k,L)); %<----- Problem?
axis tight
title(['k = ' num2str(k)]);

with my function kNNdbEval being:

function dbEval = kNNdbEval(x,y,X1,X2,k,L);
%Calculates decision boundary by eg. 2.116 in Pattern Recognition
%
%X1:Data from class 1
%X2:Data from class 2
%x:1. coordinate of point to evaluate
%y:2. coordinate of point to evaluate
%k:nearest neighbor parameters

%dbEval=x.^2+y*x+sqrt(x.^2+y.^2);

[N1 d] = size(X1);
[N2 d] = size(X2);

%Estimate priors
N = N1+N2;
p1 = N1/N;
p2 = N2/N;

[~, d1] = knnsearch(X1,[x y],'k',k);
d1 = d1(k);

[~, d2] = knnsearch(X2,[x y],'k',k);
d2=d2(k);

dbEval = (N2*(1/(d2)^d))/(N1*(1/(d1)^d)) ...
    -((p2*(L(2,1)-L(2,2)))/(p1*(L(1,2)-L(1,1)))); 

I belive my classifier is functioning correctly, as I can hack out an approximation to the decision boundary by evaluating lots of points in the plane where the points lie and plot an image of where kNNdbEval is close to zero. See the attached image.

My suspicion is that the function (being made up of two knn-searches) does not necessarily become exactly zero at any point, but I am interested in detecting when it flips from positive to negative. Any ideas of either getting ezplot to work to this end, or by some other method?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:36:11+00:00Added an answer on May 27, 2026 at 2:36 am

    I figured out how to do it using a downloaded toolbox which worked really well:
    http://cmp.felk.cvut.cz/cmp/software/stprtool/dwstprtool.html

    Details on how to proceed to get the attached figure can be understood from pboundary.m in the package:
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to visualize some data I have stored on a regular grid using
I have a very large possible data set that I am trying to visualize
Trying to get my css / C# functions to look like this: body {
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
In my WPF application im trying to visualize some temperature data. I have a
I'm trying to visualize Mandelbrot set with OpenGL and have found very strange behaviour
I'm trying to create a program which will visualize different sorting algorithms by drawing
I'm trying to visualize the history of my source-code repository using Graphviz in the
I am trying to visualize a flickr dataset using protovis. I do understand the
I'm trying to visualize 2 successive images using OpenCV Here are the 3 matrices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.