'Density plot singular matrix error in python

I am trying to visualize density plot with 36 features but I am getting error. I have set the layout to be 6 by 6 that is 6 rows and columns. I dont know what to do on it. Kindly assist to get rid of it Below is the code snippet

HR_data_le.plot(kind = 'density', subplots=True, layout=(6,6), sharex = False, sharey = False)
plt.subplots_adjust(left=0.1,bottom=0.1,  right=0.9, top=0.9,  wspace=0.4, hspace=0.4)  
plt.gcf().set_size_inches(20,20)
plt.show()

Here is the output

---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
Input In [60], in <cell line: 1>()
----> 1 HR_data_le.plot(kind = 'density', subplots=True, layout=(6,6), sharex = False, sharey = False)
      2 plt.subplots_adjust(left=0.1,bottom=0.1,  right=0.9, top=0.9,  wspace=0.4, hspace=0.4)  
      3 plt.gcf().set_size_inches(20,20)

File ~\anaconda3\lib\site-packages\pandas\plotting\_core.py:972, in PlotAccessor.__call__(self, *args, **kwargs)
    969             label_name = label_kw or data.columns
    970             data.columns = label_name
--> 972 return plot_backend.plot(data, kind=kind, **kwargs)

File ~\anaconda3\lib\site-packages\scipy\stats\kde.py:554, in gaussian_kde.set_bandwidth(self, bw_method)
    550     msg = "`bw_method` should be 'scott', 'silverman', a scalar " \
    551           "or a callable."
    552     raise ValueError(msg)
--> 554 self._compute_covariance()

File ~\anaconda3\lib\site-packages\scipy\stats\kde.py:566, in gaussian_kde._compute_covariance(self)
    562 if not hasattr(self, '_data_inv_cov'):
    563     self._data_covariance = atleast_2d(cov(self.dataset, rowvar=1,
    564                                        bias=False,
    565                                        aweights=self.weights))
--> 566     self._data_inv_cov = linalg.inv(self._data_covariance)
    568 self.covariance = self._data_covariance * self.factor**2
    569 self.inv_cov = self._data_inv_cov / self.factor**2

File ~\anaconda3\lib\site-packages\scipy\linalg\basic.py:968, in inv(a, overwrite_a, check_finite)
    966     inv_a, info = getri(lu, piv, lwork=lwork, overwrite_lu=1)
    967 if info > 0:
--> 968     raise LinAlgError("singular matrix")
    969 if info < 0:
    970     raise ValueError('illegal value in %d-th argument of internal '
    971                      'getrf|getri' % -info)

LinAlgError: singular matrix


Solution 1:[1]

The problem with the plot is that the density plot will not accept feature with a unique value, therefore, the best way to deal with it is to drop the features that contain a unique feature

Solution 2:[2]

Assuming a pure cron definition (not a cron-based extended library), that is not possible as cron definitions are simple pattern matching and lack conditionals. I.e. you can match "minute=20" and "minute=30" but not "minute=20 if hour=2 or hour=22".

If you're willing to loosen up your requirement a bit you can achieve e.g. 2:30, 12:30, 22:30 with: 30 2,12,22 * * *

An other option is over-express and then implement the condition in the triggered code.

20,30 2,12,22 * * * would give you 2:20, 2:30, 12:20, 12:30, 22:20, 22:30, then check in the triggered code whether the trigger corresponds to one of 02:20, 12:30, 22:20.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AKinsoji Hammed Adisa
Solution 2 G.G