prince icon indicating copy to clipboard operation
prince copied to clipboard

color labels raise error

Open AntoineHo opened this issue 4 years ago β€’ 3 comments

Hello, I am trying to do a PCA on my dataset, it works fine unless I try to use the color_labels argument. If I only use labels=my_labels it works.

Any idea of how I can solve this ? (It also works with the iris dataset however I can find no difference of object types or format with my own dataset.) Here is the output error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-148-819c7c4bd71a> in <module>
      1 fig, ax = plt.subplots(figsize=(12,12))
----> 2 pca.plot_row_coordinates(to_pca, ax=ax, x_component=0, y_component=1, color_labels=a, ellipse_fill=True)
      3 plt.show()

~/anaconda3/envs/biopython/lib/python3.7/site-packages/prince/pca.py in plot_row_coordinates(self, X, ax, figsize, x_component, y_component, labels, color_labels, ellipse_outline, ellipse_fill, show_points, **kwargs)
    223                 # Plot ellipse
    224                 if (ellipse_outline or ellipse_fill):
--> 225                     x_mean, y_mean, width, height, angle = plot.build_ellipse(x[mask], y[mask])
    226                     ax.add_patch(mpl.patches.Ellipse(
    227                         (x_mean, y_mean),

~/anaconda3/envs/biopython/lib/python3.7/site-packages/prince/plot.py in build_ellipse(X, Y)
     44 
     45     cov_matrix = np.cov(np.vstack((X, Y)))
---> 46     U, s, V = linalg.svd(cov_matrix, full_matrices=False)
     47 
     48     chi_95 = np.sqrt(4.61)  # 90% quantile of the chi-square distribution

~/anaconda3/envs/biopython/lib/python3.7/site-packages/scipy/linalg/decomp_svd.py in svd(a, full_matrices, compute_uv, overwrite_a, check_finite, lapack_driver)
    107 
    108     """
--> 109     a1 = _asarray_validated(a, check_finite=check_finite)
    110     if len(a1.shape) != 2:
    111         raise ValueError('expected matrix')

~/anaconda3/envs/biopython/lib/python3.7/site-packages/scipy/_lib/_util.py in _asarray_validated(a, check_finite, sparse_ok, objects_ok, mask_ok, as_inexact)
    237             raise ValueError('masked arrays are not supported')
    238     toarray = np.asarray_chkfinite if check_finite else np.asarray
--> 239     a = toarray(a)
    240     if not objects_ok:
    241         if a.dtype is np.dtype('O'):

~/anaconda3/envs/biopython/lib/python3.7/site-packages/numpy/lib/function_base.py in asarray_chkfinite(a, dtype, order)
    496     if a.dtype.char in typecodes['AllFloat'] and not np.isfinite(a).all():
    497         raise ValueError(
--> 498             "array must not contain infs or NaNs")
    499     return a
    500 

ValueError: array must not contain infs or NaNs

Thanks!

AntoineHo avatar Aug 01 '19 10:08 AntoineHo

Hello! Can you please provide a more detailed example?

MaxHalford avatar Aug 23 '19 17:08 MaxHalford

Same here with the issue.

ValueError: array must not contain infs or NaNs

YukunYangNPF avatar Dec 18 '20 05:12 YukunYangNPF

Same issue when using more than 2 labels.

valentynbez avatar Aug 23 '21 11:08 valentynbez

Hello there πŸ‘‹

I apologise for not answering earlier. I was not maintaining Prince anymore. However, I have just refactored the entire codebase. This refactoring should have fixed many bugs.

I don’t have time and energy to check if this fixes your issue, but there is a good chance it does. Feel free to reopen this issue if the problem persists after installing the new version β€” that is, version 0.8.0 and onwards.

MaxHalford avatar Feb 27 '23 11:02 MaxHalford