Calculate the local weights using the weight_matrix function on training data. Return the weighted matrix.
(
point: np.mat, training_data_x: np.mat, training_data_y: np.mat, bandwidth: float
)
| 25 | |
| 26 | |
| 27 | def local_weight( |
| 28 | point: np.mat, training_data_x: np.mat, training_data_y: np.mat, bandwidth: float |
| 29 | ) -> np.mat: |
| 30 | """ |
| 31 | Calculate the local weights using the weight_matrix function on training data. |
| 32 | Return the weighted matrix. |
| 33 | """ |
| 34 | weight = weighted_matrix(point, training_data_x, bandwidth) |
| 35 | W = (training_data.T * (weight * training_data)).I * ( |
| 36 | training_data.T * weight * training_data_y.T |
| 37 | ) |
| 38 | return W |
| 39 | |
| 40 | |
| 41 | def local_weight_regression( |
no test coverage detected