Python scikit learn pca.explained_variance_ratio_ cutoff

后端 未结 3 1162
甜味超标
甜味超标 2020-12-23 21:05

When choosing the number of principal components (k), we choose k to be the smallest value so that for example, 99% of variance, is retained.

However, in the Pytho

3条回答
  •  甜味超标
    2020-12-23 21:47

    Although this question is older than 2 years i want to provide an update on this. I wanted to do the same and it looks like sklearn now provides this feature out of the box.

    As stated in the docs

    if 0 < n_components < 1 and svd_solver == ‘full’, select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components

    So the code required is now

    my_model = PCA(n_components=0.99, svd_solver='full')
    my_model.fit_transform(my_matrix)
    

提交回复
热议问题