Calculate the weight for every point in the data set. It takes training_point , query_point, and tau Here Tau is not a fixed value it can be varied depends on output. tau --> bandwidth xmat -->Training data point --> the x where we want to make predictions
(point: np.mat, training_data_x: np.mat, bandwidth: float)
| 5 | |
| 6 | # weighted matrix |
| 7 | def weighted_matrix(point: np.mat, training_data_x: np.mat, bandwidth: float) -> np.mat: |
| 8 | """ |
| 9 | Calculate the weight for every point in the |
| 10 | data set. It takes training_point , query_point, and tau |
| 11 | Here Tau is not a fixed value it can be varied depends on output. |
| 12 | tau --> bandwidth |
| 13 | xmat -->Training data |
| 14 | point --> the x where we want to make predictions |
| 15 | """ |
| 16 | # m is the number of training samples |
| 17 | m, n = np.shape(training_data_x) |
| 18 | # Initializing weights as identity matrix |
| 19 | weights = np.mat(np.eye((m))) |
| 20 | # calculating weights for all training examples [x(i)'s] |
| 21 | for j in range(m): |
| 22 | diff = point - training_data[j] |
| 23 | weights[j, j] = np.exp(diff * diff.T / (-2.0 * bandwidth**2)) |
| 24 | return weights |
| 25 | |
| 26 | |
| 27 | def local_weight( |