pyFTS/probabilistic/kde.py
Petrônio Cândido de Lima e Silva 9bfd931e45 - Improvements on probability distributions and KDE
- Seasonal Ensemble
2017-07-01 19:42:45 -03:00

24 lines
580 B
Python

"""
Kernel Density Estimation
"""
class KernelSmoothing(object):
"""Kernel Density Estimation"""
def __init__(self,h, method="epanechnikov"):
self.h = h
self.method = method
def kernel(self, u):
if self.method == "epanechnikov":
return (3/4) * (1 - u**2)
elif self.method == "gaussian":
return 0.5
elif self.method == "uniform":
return 0.5
def probability(self, x, data):
l = len(data)
p = sum([self.kernel((x - k)/self.h) for k in data]) / l*self.h
return p