<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264646</link>
    <title>MATLAB Central Newsreader - classify in 3D</title>
    <description>Feed for thread: classify in 3D</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 31 Oct 2009 13:35:04 -0400</pubDate>
      <title>classify in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264646#691168</link>
      <author>basalganglia Sch?necker</author>
      <description>Hallo, &lt;br&gt;
&lt;br&gt;
I have data similar to that of the fisheriris data in the classification demo on &lt;a href=&quot;http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html&quot;&gt;http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/classdemo.html&lt;/a&gt;&lt;br&gt;
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 &quot;line&quot; in 3D when applying the quadratic type of classification. &lt;br&gt;
&lt;br&gt;
In the demo in with 2 variables, the curve is described by the following formula 'f':&lt;br&gt;
K = coeff(1,2).const;&lt;br&gt;
L = coeff(1,2).linear; &lt;br&gt;
Q = coeff(1,2).quadratic;&lt;br&gt;
f = sprintf('0 = %g+%g*x+%g*y+%g*x^2+%g*x.*y+%g*y.^2',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;K,L,Q(1,1),Q(1,2)+Q(2,1),Q(2,2));&lt;br&gt;
h2 = ezplot(f,[4.5 8 2 4]);&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Much thanks, Thomas</description>
    </item>
    <item>
      <pubDate>Mon, 02 Nov 2009 23:02:10 -0500</pubDate>
      <title>Re: classify in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264646#691599</link>
      <author>Tom Lane</author>
      <description>&amp;gt; I have data similar to that of the fisheriris data in the classification &lt;br&gt;
&amp;gt; demo&lt;br&gt;
. . .&lt;br&gt;
&amp;gt; How would I extend the formula for 3 variables ? It seems that the order &lt;br&gt;
&amp;gt; of the coefficients provided by classify is not further documented in &lt;br&gt;
&amp;gt; detail.&lt;br&gt;
&lt;br&gt;
Thomas, the example picks apart the coefficient arrays into separate scalars &lt;br&gt;
so they can be conveniently used in a two-dimensional example. The intent is &lt;br&gt;
that the coefficients are documented using the following matrix-oriented &lt;br&gt;
expression given in the help:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0 &amp;lt; K + x*L + x*Q*x'&lt;br&gt;
&lt;br&gt;
To plot this, the isosurface function may be useful. I don't know of an &lt;br&gt;
easier way. Try this:&lt;br&gt;
&lt;br&gt;
% Get 3 measurements from 2 iris species&lt;br&gt;
load fisheriris&lt;br&gt;
rows = 51:150;&lt;br&gt;
X = meas(rows,1:3);&lt;br&gt;
x = X(:,1); y = X(:,2); z = X(:,3);&lt;br&gt;
s = species(rows);&lt;br&gt;
a = 1:50; b = 51:100;&lt;br&gt;
&lt;br&gt;
% Do quadratic classification and get coefficients of boundary&lt;br&gt;
[c,err,post,logl,str] = classify(X,X,s,'quadratic');&lt;br&gt;
K = str(1,2).const;&lt;br&gt;
L = str(1,2).linear;&lt;br&gt;
Q = str(1,2).quadratic;&lt;br&gt;
&lt;br&gt;
% Plot the data and curve K + [x,y,z]*L + [x,y,z]*Q*[x,y,z]' = 0:&lt;br&gt;
xv = linspace(4.5,8,10); % vectors to cover the range of each column&lt;br&gt;
yv = linspace(2,4,10);&lt;br&gt;
zv = linspace(2.5,7,10);&lt;br&gt;
[xx,yy,zz] = meshgrid(xv,yv,zv);&lt;br&gt;
f = @(x,y,z) K + [x y z]*L + sum([x y z] .* ([x y z]*Q), 2);&lt;br&gt;
v = f(xx(:),yy(:),zz(:));&lt;br&gt;
v = reshape(v,size(xx));&lt;br&gt;
plot3(x(a),y(a),z(a),'rv', x(b),y(b),z(b),'b^');&lt;br&gt;
hold on&lt;br&gt;
isosurface(xx,yy,zz,v,0);&lt;br&gt;
hold off&lt;br&gt;
&lt;br&gt;
-- Tom </description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 00:37:02 -0500</pubDate>
      <title>Re: classify in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264646#691614</link>
      <author>Thomas schoenecker</author>
      <description>Hallo Tom,&lt;br&gt;
&lt;br&gt;
Your help solved my problem. Thank You very much.&lt;br&gt;
&lt;br&gt;
Thomas&lt;br&gt;
&amp;nbsp;&quot;Tom Lane&quot; &amp;lt;tlane@mathworks.com&amp;gt; wrote in message &amp;lt;hcnodi$aob$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I have data similar to that of the fisheriris data in the classification &lt;br&gt;
&amp;gt; &amp;gt; demo&lt;br&gt;
&amp;gt; . . .&lt;br&gt;
&amp;gt; &amp;gt; How would I extend the formula for 3 variables ? It seems that the order &lt;br&gt;
&amp;gt; &amp;gt; of the coefficients provided by classify is not further documented in &lt;br&gt;
&amp;gt; &amp;gt; detail.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thomas, the example picks apart the coefficient arrays into separate scalars &lt;br&gt;
&amp;gt; so they can be conveniently used in a two-dimensional example. The intent is &lt;br&gt;
&amp;gt; that the coefficients are documented using the following matrix-oriented &lt;br&gt;
&amp;gt; expression given in the help:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     0 &amp;lt; K + x*L + x*Q*x'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; To plot this, the isosurface function may be useful. I don't know of an &lt;br&gt;
&amp;gt; easier way. Try this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Get 3 measurements from 2 iris species&lt;br&gt;
&amp;gt; load fisheriris&lt;br&gt;
&amp;gt; rows = 51:150;&lt;br&gt;
&amp;gt; X = meas(rows,1:3);&lt;br&gt;
&amp;gt; x = X(:,1); y = X(:,2); z = X(:,3);&lt;br&gt;
&amp;gt; s = species(rows);&lt;br&gt;
&amp;gt; a = 1:50; b = 51:100;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Do quadratic classification and get coefficients of boundary&lt;br&gt;
&amp;gt; [c,err,post,logl,str] = classify(X,X,s,'quadratic');&lt;br&gt;
&amp;gt; K = str(1,2).const;&lt;br&gt;
&amp;gt; L = str(1,2).linear;&lt;br&gt;
&amp;gt; Q = str(1,2).quadratic;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Plot the data and curve K + [x,y,z]*L + [x,y,z]*Q*[x,y,z]' = 0:&lt;br&gt;
&amp;gt; xv = linspace(4.5,8,10); % vectors to cover the range of each column&lt;br&gt;
&amp;gt; yv = linspace(2,4,10);&lt;br&gt;
&amp;gt; zv = linspace(2.5,7,10);&lt;br&gt;
&amp;gt; [xx,yy,zz] = meshgrid(xv,yv,zv);&lt;br&gt;
&amp;gt; f = @(x,y,z) K + [x y z]*L + sum([x y z] .* ([x y z]*Q), 2);&lt;br&gt;
&amp;gt; v = f(xx(:),yy(:),zz(:));&lt;br&gt;
&amp;gt; v = reshape(v,size(xx));&lt;br&gt;
&amp;gt; plot3(x(a),y(a),z(a),'rv', x(b),y(b),z(b),'b^');&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; isosurface(xx,yy,zz,v,0);&lt;br&gt;
&amp;gt; hold off&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- Tom &lt;br&gt;
&amp;gt; </description>
    </item>
  </channel>
</rss>

