简体   繁体   English

带有 n_components = 'mle' 和 svd_solver = 'full' 的 sklearn PCA 导致数学域错误

[英]sklearn PCA with n_components = 'mle' and svd_solver = 'full' results in math domain error

My Question is highly related to math domain error while using PCA我的问题与使用 PCA 时的数学域错误高度相关

I get the following error:我收到以下错误:

  File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 88, in _assess_dimension_(1. / spectrum_[j] - 1. / spectrum_[i])) + log(n_samples)
ValueError: math domain error

which refers to this line of code :这是指这行代码

pa += log((spectrum[i] - spectrum[j]) * (1. / spectrum_[j] - 1. / spectrum_[i])) + log(n_samples)

After looking closer i found out that the problem is caused by this part of the equation:仔细观察后,我发现问题是由等式的这一部分引起的:

(spectrum[i] - spectrum[j])

which results in 0 if these values are equal.如果这些值相等,则结果为 0。 This leads to a multiplication by 0 which results in a log(0) what causes this exception.这导致乘以 0 导致 log(0) 导致此异常。

Now my question.现在我的问题。 Is the fact this error can occur a sign that my data is bad or should the implementation handle this case?发生此错误的事实是否表明我的数据已损坏,或者实现是否应该处理这种情况? If the implementation should handle this, what way would you recommend to handle this properly?如果实现应该处理这个问题,你会推荐什么方式来正确处理这个问题? In the linked question there is already an answer to this but it doesn't look very confident to be right and hasn't any feedback.在链接的问题中已经有一个答案,但它看起来不太自信并且没有任何反馈。

Created an issue on the github repo of scikit-learn containing steps to reproduce the error.在 scikit-learn 的 github 存储库上创建了一个问题,其中包含重现错误的步骤。

This is due to an open issue inside sklearn.这是由于 sklearn 内部的一个未解决的问题。 This is confirmed here在这里得到证实

A fix to this issue was introduced in scikit-learn 0.23.0, so simply update to this version. scikit-learn 0.23.0 中引入了此问题的修复程序,因此只需更新到此版本即可。

Release Notes for scikit-learn 0.23 scikit-learn 0.23 发行说明

[MRG+1] Adress decomposition.PCA mle option problem #16224 [MRG+1] 地址分解.PCA mle 选项问题#16224

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM