MCPcopy Create free account
hub / github.com/geekcomputers/Python / weighted_matrix

Function weighted_matrix

local_weighted_learning/local_weighted_learning.py:7–24  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

5
6# weighted matrix
7def 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
27def local_weight(

Callers 1

local_weightFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected