function h=plotLRcont(w,xrange,yrange,n,k,lw,v,col) % h=plotLRcont(w,xrange,yrange,n,k,lw,v,col) % % Plot contour of logistic regression likelihood in 2D % Arguments: % w: the weights of LR % xrange,yrange: either vectors of x and y values, or just the limits % n: if xrange and/or yrange are given in the form [min max] n is the % number of steps on the grid between those limits (i.e., the resolution % of the plot). Default 300. % k: number of contour lines. Default 20 % lw: line width for the contour. Default 3. % v: if given, contour for these values is plotted (in which case k is % ignored). To plot decision boundary, pass v=0.5 % col: color of the contour (default used in contour.m is green). % Returns: % handle to the contour plot. if (nargin < 4) n=300; end if (nargin < 5) k=20; end if (nargin < 6) lw=3; end if (length(xrange)==2) xrange=xrange(1):(xrange(2)-xrange(1))/n:xrange(2); yrange=yrange(1):(yrange(2)-yrange(1))/n:yrange(2); end [xx,yy]=meshgrid(xrange,yrange); xy=[reshape(xx,1,[]);reshape(yy,1,[])]; if (length(w)>2) M=(length(w)-1)/2; XY=degexpandScale(xy,M,ones(1,length(w))); end fvalue=g(XY*w); fvalue=reshape(fvalue,size(xx)); if (nargin < 7) step=(.99-0.03)/(k-1); v=(0.03:step:.99)*(max(fvalue(:))-min(fvalue(:)))+min(fvalue(:)) else if (length(v)==1) v=[v v]; end end [c,h]=contour(xrange,yrange,fvalue,v); set(h,'LineWidth',lw); if (nargin >= 8) set(h,'Color',col); end hold on;