Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-207

False Nearest Neighbors Count

Problem

Count false nearest neighbors when increasing the embedding dimension by one. For each point in dimension `dim`, find its nearest neighbor and compare the extra next-coordinate distance to the current distance; count a point when extra / distance > threshold.

Return 0 when parameters are invalid, fewer than two embedding vectors exist, or all distances are zero.

Hint

A high false-neighbor fraction means the embedding dimension is still too small.

Test cases

case 1
in: [[1,1.1,1.2,5,5.1,5.2],1,1,1]
expected: 4
case 2
in: [[1,2,3,4,5,6],1,1,10]
expected: 0
case 3
in: [[1,2,3,4,5],2,1,0.5]
expected: 3
case 4
in: [[5,5,5,5],1,1,1]
expected: 0
Starter codePython
def false_nearest_neighbors_count(series, dim, delay, threshold):
    # Your code here
    pass

4 test cases · run your code against them in the editor