Search code examples
pythonmachine-learningpcamle

select k in PCA python skitlearn


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 .


Solution

  • 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.