Domanda

I'm performing kNN prediction of numerical variable (knn regression or Locally weighted average). I am using euclidean distance and 1/distance as weights but I don't know how this is applied. and I have question:

How exactly the weightning in WEKA IBk for regression is performed? Is this a simple function like 1/distance or something more complicated? I looked in the source code but I couldn't understand anything. And how exactly the distance is defined - is it euclidean or some modification? What that code means (this is lines 867 and 868 from IBk source code):

distances[i] = distances[i]*distances[i];
distances[i] = Math.sqrt(distances[i]/m_NumAttributesUsed);
È stato utile?

Soluzione

In kNN, weighting allows neighbors closer to the data point to have more influence on the predicted value.

For numerical regression in Weka with IBk, the weighting is performed as shown in the linked method.

I have summarized the steps in the following pseudo code.

Step 0: prediction = 0, total = 0

Step 1:

For each of the k-neighbors:

  1. Calculate distance to neighbor i

  2. Calculate weight: weight = 1 / (distance)

  3. Update prediction: prediction = prediction + neighbor i's class value * weight

  4. Update total: total = total + weight

Step 2: prediction = prediction / total

Step 3: return(prediction)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top