原理讲解
caimouse 在他的关于 Locally weighted linear regression 的文章中指出了一些基本原理的 python 代码实现。
引用他的代码是这样的
#python 3.5.3 蔡军生
#http://edu.youkuaiyun.com/course/detail/2592
# 计算加权回归
import numpy as np
import random
import matplotlib.pyplot as plt
def gaussian_kernel(x, x0, c, a=1.0):
"""
Gaussian kernel.
:Parameters:
- `x`: nearby datapoint we are looking at.
- `x0`: data point we are trying to estimate.
- `c`, `a`: kernel parameters.
"""
# Euclidian distance
diff = x - x0
dot_product = diff * diff.T
return a * np.exp(dot_product / (-2.0 * c**2))
def get_weights(training_inputs, datapoint, c=1.0):
"""
Function that calculates weight matrix for a given data point and training
data.
:Parameters:
-