python - How to get Kernels from kernel density estimation (preferrably sklearn.neighbors)? -


i'm working on seasonality estimation time series dataset.

what dataset of possible frequencies/periods might occur in dataset. thus, noisy (e.g. having periods [100, 98, 101, 102] should "the same").

for estimating sharp periods, try estimate peaks via kernel density estimation (kde, sklearn.neighbors.kerneldensity) follows:

import numpy np sklearn.neighbors import kerneldensity scipy import signal import matplotlib.pyplot plt  x1 = np.random.randint(1, 4, 20) x2 = np.random.randint(10, 13, 200) x = np.concatenate((x1, x2), axis=0) # peaks schould @ 2 , 11!  bw = 1  kde = kerneldensity(kernel='gaussian', bandwidth=bw).fit(x.reshape(-1, 1)) estimator = np.linspace(0, 15, 100) kde_est = np.exp(kde.score_samples(estimator.reshape(-1, 1)))  plt.plot(estimator, kde_est)  peaks_pos = signal.argrelextrema(kde_est, np.greater)[0]  print(estimator[peaks_pos]) # peaks @ around 2 , 11! 

additionally, i'd know how kernels estimation like. gaussian case, there should set of /mu , /sigma should available [default] 40 kernels. can access information? not find clue in documentation or details of kde attributes. i'm pretty sure, should available somehere.

for clarification, why need this:

in following example, 2 peaks close found, i'm sure kernels show up.

x1 = np.random.randint(1, 4, 20) x2 = np.random.randint(5, 8, 200) x = np.concatenate((x1, x2), axis=0) # peaks schould @ 2 , 6!  bw = 1  kde = kerneldensity(kernel='gaussian', bandwidth=bw).fit(x.reshape(-1, 1)) estimator = np.linspace(0, 15, 100) kde_est = np.exp(kde.score_samples(estimator.reshape(-1, 1)))  plt.plot(estimator, kde_est)  peaks_pos = signal.argrelextrema(kde_est, np.greater)[0]  print(estimator[peaks_pos]) # peaks @ around 6 , 2! 


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -