Home>
Always I am indebted.
I'm doing density estimation in Python
An error will occur if you increase the number of dimensions of the data.
I couldn't understand why this error occurred, so I asked a question.
(I would appreciate it if you could tell me the cause of the occurrence)
If the number of dimensions is 4 or more, the following error may occur.
The rate of occurrence is about 50%. (As the number of dimensions increases, so does the probability of error occurrence)
 
LinAlgError Traceback (most recent call last)
<ipythoninput11ce4c335d8dd1>in<module>
2 xy = np.vstack ([a1, a2, a3, a4, a5])
3 kernel = stats.gaussian_kde (xy)
>4 z_est = kernel.evaluate (xy)
~ \ program \ anaconda \ lib \ sitepackages \ scipy \ stats \ kde.py in evaluate (self, points)
244 result = zeros ((m,), dtype = float)
245
>246 whitening = linalg.cholesky (self.inv_cov)
247 scaled_dataset = dot (whitening, self.dataset)
248 scaled_points = dot (whitening, points)
~ \ program \ anaconda \ lib \ sitepackages \ scipy \ linalg \ decomp_cholesky.py in cholesky (a, lower, overwrite_a, check_finite)
89 "" "
90 c, lower = _cholesky (a, lower = lower, overwrite_a = overwrite_a, clean = True,
>91 check_finite = check_finite)
92 return c
93
~ \ program \ anaconda \ lib \ sitepackages \ scipy \ linalg \ decomp_cholesky.py in _cholesky (a, lower, overwrite_a, clean, check_finite)
38 if info>0:
39 raise LinAlgError ("% dth leading minor of the array is not positive"
>40 "definite"% info)
41 if info<0:
42 raise ValueError ('LAPACK reported an illegal value in {} th argument'
LinAlgError: 1th leading minor of the array is not positive definite
Corresponding source code
# import
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
% matplotlib inline
#Data creation (generated in texto)
N1 = np.random.normal (size = 400)
N2 = np.random.normal (scale = 0.5, size = 400)
N3 = np.random.normal (scale = 0.5, size = 400)
N4 = np.random.normal (scale = 0.5, size = 400)
N5 = np.random.normal (scale = 0.5, size = 400)
N6 = np.random.normal (scale = 0.5, size = 400)
a1 = N1 + 1 * N2
a2 = N11 * N2
a3 = N1 + 1 * N3
a4 = N11 * N3
a5 = N1 + 1 * N4
a6 = N11 * N4
a7 = N1 + 1 * N5
a8 = N11 * N5
a9 = N1 + 1 * N6
a0 = N11 * N6
#Density estimation (Error occurs when a4 or higher)
xy = np.vstack ([a1, a2, a3])
kernel = stats.gaussian_kde (xy)
z_est = kernel.evaluate (xy)
# Visualization
x = a1
y = a2
plt.scatter (x, y, c = z_est)
What I tried
No error occurred up to 3D. (I tried about 30 times)
In 4 dimensions and above, there is a 50% chance that an error will occur.
(As the number of dimensions increases, so does the probability of error occurrence)
python3.7
anaconda core i5
We would appreciate your help.

Answer # 1
Related articles
 python  i don't know the solution and cause of the attribute error that occurred when using pillow
 python  in raspberry pi, the error occurs only in the case of the automatic start program using systemd
 python  an error occurs when django's summer note is reflected in admin
 python 3x  an error occurs after registering a dictionary with a readaloud bot on discordpy
 python  an error occurs in the if statement program that compares the size of numbers
 about the cause of the error in python pdto_datetime
 python max () arg is an empty sequence and an error occurs and it cannot be processed well
 python: an error occurs that the type is different in the output using dict key values
 python  i don't know the cause of the error
 python 3x  best estimator: i get an error with no syntax, so please tell me what to do
 python  i want to display an image with pysimplegui, but an error occurs
 python  error when scraping with selenium and firefox
 [python] graphviz output format error
 python  web scraping what to do when a webdriverexception occurs on starbucks hp
 python  i get an error when connecting to a voice channel with discordpy
 python  an error has occurred in yolo v3
 an error occurs during python scraping (retrieving property information from suumo)
 [python] i don't know how to solve the error
 python  idle cannot resolve the "rootgeometry" error
 python  tuple error does not resolve
Trends
 python  you may need to restart the kernel to use updated packages error
 php  coincheck api authentication doesn't work
 php  i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
 [php] i want to get account information using coincheck api
 the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
 javascript  how to check if an element exists in puppeteer
 dart  flutter: the instance member'stars' can't be accessed in an initializer error
 sh  'aptget' is not recognized as an internal or external command, operable program or batch file
 i want to call a child component method from a parent in vuejs
 python 3x  typeerror: 'method' object is not subscriptable
It will be a selfanswer,
1: It is difficult to solve this problem (problem due to Cholesky decomposition at the time of evaluate)
2: In a library that can calculate kernel density other than sklearn, there are various problems and it can not be calculated in high dimensions (many people write that it can be done on the web, but there is no result of a proper investigation of 3 dimensions or more)
So, after all, I made the kernel density of sklaern CV and decided the bandwidth and used it.
However, sklearn has a different calculation method such as scipy, so there will be a slight difference.
(Even if there is a difference, there is no problem because both of them deviate from the true value anyway)
Probably, there seems to be no easy solution at present other than this.
I hope it helps someone.