how to determining threshold distance using knn

조회 수: 17 (최근 30일)
merlin toche
merlin toche 2023년 1월 29일
댓글: merlin toche 2024년 11월 25일 9:23
Hello everyone
please i still need you
I want to detect defects and classify them using the kNN rule. however with your help I understood a lot about knn.
now i would like to know how to set distance threshold (euclidean).
example Detection rule:
Unclassified incoming sample,Find its nearest neighbor from the training sample,Calculate its distance kNN squared for each sample. Squared kNN distance < threshold, then sample labeled as normal otherwise defective. we can set a threshold with a certain level and the unclassified sample is considered normal if its distance to its nearest neighboring training sample is less than the threshold otherwise the sample is detected as defective. can anyone help me out?. the nominal data belongs to the class
NB: does classification take the place of detection? attached my code, my data (i have 5 class)

답변 (1개)

Udit06
Udit06 2024년 11월 25일 5:41
Hi Merlin,
You can analyze the distribution of the euclidean distances for samples labeled as "normal" in your training set. This will help you understand the typical range of distances for normal samples.
To decide the threshold distance, you can consider using one of the two approaches mentioned below:
1) Use statistical measures like the mean and standard deviation of the squared distances of normal samples.
2) Alternatively, you can use a percentile (e.g., the 95th percentile) of the squared distances as the threshold.
I hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by