[Scipy-svn] r3140 - in trunk/Lib/sandbox/pyem: doc examples
scipy-svn at scipy.org
scipy-svn at scipy.org
Mon Jul 2 08:58:50 EDT 2007
Author: cdavid
Date: 2007-07-02 07:58:40 -0500 (Mon, 02 Jul 2007)
New Revision: 3140
Modified:
trunk/Lib/sandbox/pyem/doc/Makefile
trunk/Lib/sandbox/pyem/doc/index.txt
trunk/Lib/sandbox/pyem/doc/tutorial.pdf
trunk/Lib/sandbox/pyem/examples/discriminant_analysis.py
Log:
Update doc
Modified: trunk/Lib/sandbox/pyem/doc/Makefile
===================================================================
--- trunk/Lib/sandbox/pyem/doc/Makefile 2007-07-02 12:22:31 UTC (rev 3139)
+++ trunk/Lib/sandbox/pyem/doc/Makefile 2007-07-02 12:58:40 UTC (rev 3140)
@@ -1,4 +1,4 @@
-# Last Change: Sat Jun 09 05:00 PM 2007 J
+# Last Change: Mon Jul 02 09:00 PM 2007 J
# This makefile is used to build the pdf from the rest file and inlined code
# from python examples
@@ -7,7 +7,7 @@
rst2tex = PYTHONPATH=/home/david/local/lib/python2.4/site-packages rst2newlatex.py \
--stylesheet-path base.tex --user-stylesheet user.tex
-pytexfiles = pyem.tex basic_example1.tex basic_example2.tex basic_example3.tex pdfestimation.tex
+pytexfiles = pyem.tex basic_example1.tex basic_example2.tex basic_example3.tex pdfestimation.tex discriminant_analysis.tex
SOURCEPATH = $(PWD)
@@ -36,6 +36,9 @@
pdfestimation.tex: ../examples/pdfestimation.py
$(py2tex) $< > $@
+discriminant_analysis.tex: ../examples/discriminant_analysis.py
+ $(py2tex) $< > $@
+
clean:
for i in $(pytexfiles); do \
rm -f `echo $$i`; \
Modified: trunk/Lib/sandbox/pyem/doc/index.txt
===================================================================
--- trunk/Lib/sandbox/pyem/doc/index.txt 2007-07-02 12:22:31 UTC (rev 3139)
+++ trunk/Lib/sandbox/pyem/doc/index.txt 2007-07-02 12:58:40 UTC (rev 3140)
@@ -13,7 +13,7 @@
file: Bic_example.png
/restindex
-.. Last Change: Sat Jun 09 07:00 PM 2007 J
+.. Last Change: Mon Jul 02 09:00 PM 2007 J
===================================================
PyEM, a python package for Gaussian mixture models
@@ -204,8 +204,26 @@
Using PyEM for supervised learning
----------------------------------
-TODO
+The following example shows how to do classification using discriminative
+analysis on the famous iris dataset. The idea is to model each class
+distribution P(data|class) by a mixture of Gaussian, and to classify the data
+with Maximum A Posteriori (eg takes the class which maximizes P(class | data)).
+Not surprisingly, the errors lie on the border between the two classes which
+are not linearly separable.
+.. raw:: latex
+
+ \input{discriminant_analysis.tex}
+
+.. figure:: dclass.png
+ :width: 600
+ :height: 400
+
+ learning data points on the left with isodensity curves as estimated by
+ each mixture. On the right, the misclassified points are in red, green are
+ correctly classified.
+
+
Note on performances
====================
Modified: trunk/Lib/sandbox/pyem/doc/tutorial.pdf
===================================================================
(Binary files differ)
Modified: trunk/Lib/sandbox/pyem/examples/discriminant_analysis.py
===================================================================
--- trunk/Lib/sandbox/pyem/examples/discriminant_analysis.py 2007-07-02 12:22:31 UTC (rev 3139)
+++ trunk/Lib/sandbox/pyem/examples/discriminant_analysis.py 2007-07-02 12:58:40 UTC (rev 3140)
@@ -11,6 +11,7 @@
import numpy as N
import pylab as P
+import matplotlib as MPL
from scipy.sandbox import pyem
import utils
@@ -93,8 +94,11 @@
# Plot the results
#-----------------
csym = {'setosa' : 's', 'versicolor' : 'x', 'virginica' : 'o'}
-P.figure()
+r = 50.
+P.figure(figsize = [600/r, 400/r])
+prop = MPL.font_manager.FontProperties(size='smaller')
+
# Plot the learning data with the mixtures
P.subplot(2, 1, 1)
for i in lmod.values():
@@ -104,6 +108,8 @@
for i in cnames:
P.plot(ldata[i][:, 0], ldata[i][:, 1], csym[i], label = i + ' (learning)')
+P.xlabel('sepal width')
+P.ylabel('petal width')
P.legend(loc = 'best')
# Plot the results on test dataset (green for correctly classified, red for
@@ -115,5 +121,7 @@
if len(incorrect[i]) > 0:
P.plot(tx[incorrect[i]], ty[incorrect[i]], 'r' + csym[i],
label = '%s (incorrectly classified)' % i)
-P.legend(loc = 'best')
-P.show()
+P.legend(loc = 'best', prop = prop)
+P.xlabel('sepal width')
+P.ylabel('petal width')
+P.savefig('dclass.png', dpi = 60)
More information about the Scipy-svn
mailing list