Hi,
does anyone have a reference on how the distances will be calculated using the hotspot to save the distances into the data table in the following situations:
- Analyze -> Predictive Modeling -> K Nearest Neighbors -> "Variable" as "X,Faktor" -> OK -> Hotspot "Save Near Neighbor Distances"
- Analyze -> Screening -> Explore Outliers -> "Variable" as "Y, Columns" -> Multivariate: K Nearest Neighbor Outliers -> OK -> Buton "Save NN Distances"
Why am I asking:
- The results are not identical for both modules (see attached data table: "Distanz 1-4" are from 1. above, "Nächste 1 Distanz_OutlierModule 1-4" are from 2).
- None of these seem to calculate the euklidean distance (shouldn't be the first Nearest Neighbor Distance be 1 for all values/rows of variable)?) It seems that it has some calculation of the largest distance and then calculates the others based on their proportion part (0.25 as distance 1 and 1 as distance 4 (farest from variable value 1, so one forth of the max distance is the NN Distance saved, while I would expect 1,2,3,4 as NN distances for the first row in the data table). And in the modeling module the values are somehow similar (for the proportions) but different from the absolute values.
I saw the docmentation with a reference to: Hastie et al. (2009), Hand et al. (2001), and Shmueli et al. (2017). (Overview of the K Nearest Neighbors Platform ), where is mentioned it identifies the smallest Euclidean distances between the predictor values for that observation and the predictor values for each of the other observations. However, it does not explain to me the different results.
Thank you a lot! Is there a way to undo or prevent the standardization?
Although it's not documented, I wildly guess that before calculating the Euclidian distances, the K-Nearest Neighbours platform standardized by (x_i - m_i)/s_i where m_i is the mean and s_i is the stddev for the x_i.
Clear Globals();
x = [1,2,3,4,5];
s = Stddev(x);
m = Mean(x);
z = (x - m)/s;
n = Number(x);
dist_z = J(n, n, 0);
For(i = 1, i <= n - 1, i++,
For(j = 1, j <= n, j++,
dist_z[i, j] = dist_z[j, i] = Sqrt(Sum((z[i,0]-z[j,0])^2));
)
);
Show(dist_z);
The following entries in Sirius say that the variables are standardized by Q90 - Q10 on the Explorer Outliers platform.
https://sirius.na.sas.com/Sirius/GSTS/ShowTrack.aspx?trknum=7612927109
https://sirius.na.sas.com/Sirius/GSTS/ShowTrack.aspx?trknum=7612540893
Clear Globals();
x = [1,2,3,4,5];
n = Number(x);
q90 = Quantile(0.9, x);
q10 = Quantile(0.1, x);
mid = (q90 + q10)/2;
range = q90 - q10;
w = (x - mid)/range;
dist_w = J(n, n, 0);
For(i = 1, i <= n - 1, i++,
For(j = 1, j <= n, j++,
dist_w[i, j] = dist_w[j, i] = Sqrt(Sum((w[i,0]-w[j,0])^2));
)
);
Show(dist_w);