Skip to content

Commit

Permalink
the code forget normalized inverse of the distance
Browse files Browse the repository at this point in the history
your: Batch #1 MSE: 14.38
After correction: Batch #1 MSE: 10.625
"We also have to choose how to weight the distances. A straight forward way to weight the distances is by the distance itself. Points that are further away from our prediction should have less impact than nearer points. The most common way to weight is by the normalized inverse of the distance."--according to your "Nearest Neighbor Methods Introduction".
  • Loading branch information
yuanxiaosc committed Nov 22, 2018
1 parent befbf03 commit f4a260a
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
# Predict: Get min distance index (Nearest neighbor)
#prediction = tf.arg_min(distance, 0)
top_k_xvals, top_k_indices = tf.nn.top_k(tf.negative(distance), k=k)
top_k_xvals = tf.truediv(1.0, top_k_xvals)
x_sums = tf.expand_dims(tf.reduce_sum(top_k_xvals, 1),1)
x_sums_repeated = tf.matmul(x_sums,tf.ones([1, k], tf.float32))
x_val_weights = tf.expand_dims(tf.div(top_k_xvals,x_sums_repeated), 1)
Expand Down

0 comments on commit f4a260a

Please sign in to comment.