Thread Subject: classify in 3D

Subject: classify in 3D

From: basalganglia Sch?necker

Date: 31 Oct, 2009 13:35:04

Message: 1 of 3

Hallo,

I have data similar to that of the fisheriris data in the classification demo on http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html
The demo is exactly what I want to do with my data. However, I use 3 variables instead of the 2 shown in the demo (3D position in space). The classification works fine but now the problem is how to visualize the classification "line" in 3D when applying the quadratic type of classification.

In the demo in with 2 variables, the curve is described by the following formula 'f':
K = coeff(1,2).const;
L = coeff(1,2).linear;
Q = coeff(1,2).quadratic;
f = sprintf('0 = %g+%g*x+%g*y+%g*x^2+%g*x.*y+%g*y.^2',...
            K,L,Q(1,1),Q(1,2)+Q(2,1),Q(2,2));
h2 = ezplot(f,[4.5 8 2 4]);

How would I extend the formula for 3 variables ? It seems that the order of the coefficients provided by classify is not further documented in detail.

Much thanks, Thomas

Subject: classify in 3D

From: Tom Lane

Date: 2 Nov, 2009 23:02:10

Message: 2 of 3

> I have data similar to that of the fisheriris data in the classification
> demo
. . .
> How would I extend the formula for 3 variables ? It seems that the order
> of the coefficients provided by classify is not further documented in
> detail.

Thomas, the example picks apart the coefficient arrays into separate scalars
so they can be conveniently used in a two-dimensional example. The intent is
that the coefficients are documented using the following matrix-oriented
expression given in the help:

    0 < K + x*L + x*Q*x'

To plot this, the isosurface function may be useful. I don't know of an
easier way. Try this:

% Get 3 measurements from 2 iris species
load fisheriris
rows = 51:150;
X = meas(rows,1:3);
x = X(:,1); y = X(:,2); z = X(:,3);
s = species(rows);
a = 1:50; b = 51:100;

% Do quadratic classification and get coefficients of boundary
[c,err,post,logl,str] = classify(X,X,s,'quadratic');
K = str(1,2).const;
L = str(1,2).linear;
Q = str(1,2).quadratic;

% Plot the data and curve K + [x,y,z]*L + [x,y,z]*Q*[x,y,z]' = 0:
xv = linspace(4.5,8,10); % vectors to cover the range of each column
yv = linspace(2,4,10);
zv = linspace(2.5,7,10);
[xx,yy,zz] = meshgrid(xv,yv,zv);
f = @(x,y,z) K + [x y z]*L + sum([x y z] .* ([x y z]*Q), 2);
v = f(xx(:),yy(:),zz(:));
v = reshape(v,size(xx));
plot3(x(a),y(a),z(a),'rv', x(b),y(b),z(b),'b^');
hold on
isosurface(xx,yy,zz,v,0);
hold off

-- Tom

Subject: classify in 3D

From: Thomas schoenecker

Date: 3 Nov, 2009 00:37:02

Message: 3 of 3

Hallo Tom,

Your help solved my problem. Thank You very much.

Thomas
 "Tom Lane" <tlane@mathworks.com> wrote in message <hcnodi$aob$1@fred.mathworks.com>...
> > I have data similar to that of the fisheriris data in the classification
> > demo
> . . .
> > How would I extend the formula for 3 variables ? It seems that the order
> > of the coefficients provided by classify is not further documented in
> > detail.
>
> Thomas, the example picks apart the coefficient arrays into separate scalars
> so they can be conveniently used in a two-dimensional example. The intent is
> that the coefficients are documented using the following matrix-oriented
> expression given in the help:
>
> 0 < K + x*L + x*Q*x'
>
> To plot this, the isosurface function may be useful. I don't know of an
> easier way. Try this:
>
> % Get 3 measurements from 2 iris species
> load fisheriris
> rows = 51:150;
> X = meas(rows,1:3);
> x = X(:,1); y = X(:,2); z = X(:,3);
> s = species(rows);
> a = 1:50; b = 51:100;
>
> % Do quadratic classification and get coefficients of boundary
> [c,err,post,logl,str] = classify(X,X,s,'quadratic');
> K = str(1,2).const;
> L = str(1,2).linear;
> Q = str(1,2).quadratic;
>
> % Plot the data and curve K + [x,y,z]*L + [x,y,z]*Q*[x,y,z]' = 0:
> xv = linspace(4.5,8,10); % vectors to cover the range of each column
> yv = linspace(2,4,10);
> zv = linspace(2.5,7,10);
> [xx,yy,zz] = meshgrid(xv,yv,zv);
> f = @(x,y,z) K + [x y z]*L + sum([x y z] .* ([x y z]*Q), 2);
> v = f(xx(:),yy(:),zz(:));
> v = reshape(v,size(xx));
> plot3(x(a),y(a),z(a),'rv', x(b),y(b),z(b),'b^');
> hold on
> isosurface(xx,yy,zz,v,0);
> hold off
>
> -- Tom
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
3d discrimant a... Thomas Schoenecker 31 Oct, 2009 09:39:01
rssFeed for this Thread

Contact us at files@mathworks.com