Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a conflict between matplotlib and PCA #17788

Closed
hewenkui opened this issue Jun 30, 2020 · 4 comments
Closed

There is a conflict between matplotlib and PCA #17788

hewenkui opened this issue Jun 30, 2020 · 4 comments

Comments

@hewenkui
Copy link

Using sklearn.decomposition.PCA, if the matplotlib library is used to draw a picture, there will be an exception ( numpy.linalg.LinAlgError)

The test code(windows x64, matplotlib==3.2.2, scipy==1.5.0, numpy==1.19.0):

import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pylab as plt

def save_pic():
    fig = plt.figure(figsize=(12, 6))
    ax = fig.add_axes([0.1, 0.13, 0.85, 0.80])
    ax.plot([0, 1], [0, 1], 'k--')
    fig.savefig('./a.png')
    plt.close(fig)

def test(is_call_save_pic):
    a = np.arange(1200).reshape((30, -1))
    if is_call_save_pic:
        save_pic()
    pca = PCA(n_components=2)
    pca.fit(a)
    print('OK')

if __name__ == '__main__':
    test(False)
    try:
        test(True)
    except np.linalg.LinAlgError as e:
        print(e)
@glemaitre
Copy link
Member

I cannot reproduce on linux.

@LilianBoulard
Copy link
Contributor

Could not reproduce either on Windows 10 x64 (with scikit-learn 0.23.2 and specified numpy, scipy and matplotlib versions).

@NicolasHug
Copy link
Member

Thanks @glemaitre and @Phaide for trying to reproduce the bug. @hewenkui can you try again with the latest version and confirm whether you still observe the exception? thanks

@thomasjpfan
Copy link
Member

As suggested in the related issue: #19285 (comment) , the solution is to update NumPy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants