I'm looking for a way to get the kernel density function of a data set and plot it for arbitrary data points. Using Scipy stats module, I came up with the following code:
import numpy as np
import scipy.stats as st
def get_pdf(data):
a = np.array(data)
ag = st.gaussian_kde(a)
x = np.linspace(0, max(data), max(data)*10)
y = ag(x)
return x, y
This gives the expected result, but the performance is very poor, when the data set size is large.
I found fastkde as an implementation for fast kernel density estimation. But I could not figure out a way to use this in the same way I used Scipy stats KDE.
Can someone give me some insight?
Thanks