Kurve ist einfach zu sehen, aber schwer zu beschreiben
Idee: Vorhersage für neuen Punkt $x$ über Regression "in der Nähe" von $x$.
Auch bekannt als: LOESS (locally estimated scatterplot smoothing)
Wir haben Trainingsdaten \[\mathcal{D}_\text{train} = [(x_1, y_1), (x_2, y_2), \ldots, (x_m, y_m)]\] und wollen $x$ vorhersagen.
Jedem Trainingsbeispiel geben wir ein Gewicht
$u(x_i, x) = e^{\frac{|x_i - x|}{2 \tau^2}}$
Berechne Regressionsgewichte $w_x$ basierend auf Loss Funktion
\[ \operatorname{TrainLoss}_\text{LOESS}(w {\color{red}, x}) = \frac{1}{m} \sum_{(x',y') \in \mathcal{D}_\text{train}} {\color{red} u(x', x)}( h_w(x') - y' )^2 \]
Anschließend ist unsere Vorhersage \[ h(x) = w_x \cdot \phi(x) \]
class LocallyWeightedRegression:
def __init__(self, tau = 1):
self.tau = tau
def fit(self, X, Y):
self.X = np.copy(X)
self.Y = np.copy(Y)
def local_regression(self, x):
U = np.exp(- np.linalg.norm(self.X - x, axis=1) / (2 * self.tau ** 2))
regression = LinearRegression()
regression.fit(self.X, self.Y, U)
return regression.predict([x])[0]
def predict(self, X):
return [self.local_regression(x) for x in X]
Wie wählen wir $\tau$ in $u(x_i, x) = e^{\frac{|x_i - x|}{2 \tau^2}}$?
Ausprobieren!
Vorteile
Nachteile
Non parametric Model
Wir haben keine fixe Anzahl Gewichte, die von der Größe des Datensatzes unabhängig ist.