if window_size % 2 != 1 or window_size < 1:
    raise TypeError('window_size size must be a positive odd number')
if window_size < order + 2:
    raise TypeError('window_size is too small for the polynomials order')
order_range = list(range(order + 1))
half_window = (window_size - 1) // 2
b = np.mat([[(k ** i) for i in order_range] for k in range(-half_window, 
    half_window + 1)])
m = np.linalg.pinv(b).A[deriv] * rate ** deriv * factorial(deriv)
firstvals = y[0] - np.abs(y[1:half_window + 1][::-1] - y[0])
lastvals = y[-1] + np.abs(y[-half_window - 1:-1][::-1] - y[-1])
y = np.concatenate((firstvals, y, lastvals))
return np.convolve(m[::-1], y, mode='valid')
how to smooth a curve in python