Created
November 8, 2015 12:04
-
-
Save dtanham/1f2b06c48a975c4354d7 to your computer and use it in GitHub Desktop.
LOESS implementation in Python - courtesy of Phillip K Janert's O'Reilly book Data Analysis with Open Source Tools (aka the bible)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pylab import * | |
# # x: location; h: bandwidth; xp, yp: data points (vectors) | |
def loess( x, h, xp, yp): | |
w = exp( -0.5*( ((x-xp)/h)**2)/sqrt(2*pi*h**2) ) | |
b = sum(w*xp)*sum(w*yp) - sum(w)*sum(w*xp*yp) | |
b /= sum(w*xp)**2 - sum(w)*sum(w*xp**2) | |
a = ( sum(w*yp) - b*sum(w*xp) )/sum(w) | |
return a + b*x | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment