[Tutor] HELP- Regarding working with python
Lie Ryan
lie.1296 at gmail.com
Fri Jan 18 09:25:44 CET 2013
On 18/01/13 17:11, Gayathri S wrote:
> hi...
> I am using principal component analysis for dimensionality
> reduction in python. am having this following error...
> >>> import numpy as np
> >>> import matplotlib.pyplot as plt
> >>> import mlpy
> >>> np.random.seed(0)
> >>> mean,cov,n=[0,0],[[1,1],[1,1.5]],100
> >>> x=np.random.multivariate_normal(mean,cov,n)
> >>> pca.learn(x)
> Traceback (most recent call last):
> File "<interactive input>", line 1, in <module>
> NameError: name 'pca' is not defined
> >>>
> would you please help me in finding the error...? what was my fault? how
> could i use PCA in python..?
You might want to start with a more basic tutorials for working with
python, for example the official tutorial at
http://docs.python.org/2/tutorial/ You should go through at least the
first 5-6 chapters, which should take no more than several hours to skim
through if you already have experience in any other languages.
As in your particular problem, the basic issue is that you have not
defined 'pca' to refer to any object. You need to create an object named
pca, which in this particular case the object is probably an instance of
mlpy.PCA, which can be constructed like this:
pca = mlpy.PCA()
More information about the Tutor
mailing list