Is it possible to obtain a KDE for periodic data in sklearn or a different Python package?
Here is a simplified example: I am creating a mockup dataset from two normal distributions and map it to the interval from 0 to 20.
import numpy as np
import matplotlib.pyplot as plt
# create dataset
data = np.hstack((np.random.normal(8, 2, 200), np.random.normal(19, 4, 200))) % 20
When I plot the result of the KDE
# fit
from sklearn.neighbors import KernelDensity
kde = KernelDensity(bandwidth=1, kernel='gaussian')
kde.fit(data[:, None])
# plot
x_d = np.linspace(0, 20, 100)
logprob = kde.score_samples(x_d[:, None])
plt.fill_between(x_d, np.exp(logprob), alpha=0.5)
plt.hist(data, histtype = "step", density = True)
plt.ion()
plt.show()
it (obviously) does not know about the periodicity of the data:
as you can see from the estimate having three peaks and being non-smooth at the boundaries.
