astrochris
astrochris

Reputation: 1866

running PCA analysis matplotlib results print <matplotlib.mlab.PCA instance at 0xffa4ee6c>

I am trying to do a PCA analysis of some data using the matplotlib function however when I run it and try to print the results this gets printed as the results

import numpy as np
import os
import matplotlib
from matplotlib.mlab import PCA




x=np.zeros((62,2))
a=np.genfromtxt('1.txt').T[3] #list 62numbers
#print a
x[:,0]=a
print x[:,0]
b=np.genfromtxt('2.txt').T[3] #list 4numbers
x[:,1]=b
#print x
results=PCA(x)

print results

the result that gets printed is matplotlib.mlab.PCA instance at 0xffa4ee6c why is that?

Upvotes: 0

Views: 418

Answers (1)

user861537
user861537

Reputation:

If you look at the documentation for matplotlib.mlab.PCA you see from the header

class matplotlib.mlab.PCA(a)

that it is actually a class you are dealing with. When you do PCA(x) you are creating an instance of that class, and when you print it in the following line you are told that you have got yourself an instance of matplotlib.mlab.PCA. You can confirm this by printing the output of dir(results), where you'll see what attributes you have on the object. It can helpful to determine what object you are dealing with.

What you want to do here is to use the attributes of this object you've got. For instance,

print results.Y  # print the projection in PCA space

Upvotes: 5

Related Questions