pyFTS/probabilistic/kde.py
Petrônio Cândido de Lima e Silva ff67356d64 - Issue #3 - Code documentation with PEP 257 compliance
- Benchmarks refactoring and optimizations
 - Probabilistic package, with Kernel Density Estimation
2017-05-08 13:12:08 -03:00

25 lines
614 B
Python

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