-2

I am trying to use the skitlearn package for PCA .In the documentation website given here http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html

it is said that if n_components == ‘mle’, then mle is used to find the number of principal components but when I run my code

X_reduced = PCA(n_components=mle).fit_transform(self.X)

it gives an error message saying that

global name 'mle' is not defined

how can I specify that mle method has to be used .

alexander
  • 21
  • 7

1 Answers1

1

Put mle in quotes, like it is mentioned in the documentation.

X_reduced = PCA(n_components='mle').fit_transform(self.X)

The thing is when you say mle instead of 'mle', it is referring to variable, which is not defined in your case.

Sagar Waghmode
  • 767
  • 5
  • 16
  • "Put mle in quotes like the document says" would be more like it. Although you might want to add some explanation about why it raises a NameError without the quotes. – Tadhg McDonald-Jensen Mar 25 '16 at 06:23