def _loess_predict(X, y_tr, X_pred, bandwidth):
X_tr = np.column_stack((np.ones_like(X), X))
X_te = np.column_stack((np.ones_like(X_pred), X_pred))
y_te = []
for x in X_te:
ws = np.exp(-np.sum((X_tr - x)**2, axis=1) / (2 * bandwidth**2))
W = scipy.sparse.dia_matrix((ws, 0), shape=(X_tr.shape[0],) * 2)
theta = np.linalg.pinv(X_tr.T.dot(W.dot(X_tr))).dot(X_tr.T.dot(W.dot(y_tr)))
y_te.append(np.dot(x, theta))
return np.array(y_te)
评论列表
文章目录