Link to home
Start Free TrialLog in
Avatar of shelley hanson
shelley hanson

asked on

Can someone help me me how to do this?

Hi I need to write a function knnOutliers(v, k, t) that takes a list argument v (which contain a list of points, where each point is a tuple containing two real-valued numbers), an integer argument k (corresponding to the number of neighbours of interest) and a positive real-valued argument t (specifying the threshold used to test whether a point is an outlier), and returns the list of indexes of the outlier points (if any) in the data sequence v. We can assume that k≥1, and that there are at least k+1 points in v. If our output list contains multiple output indexes, the indexes should appear in increasing order (see the third example below). If no outliers are detected, the function should return an empty list. We need to calculate the Euclidean distance between two points and sort the numbers using sort () :)). Thank you!!
Here is an example :
>>> print(knnOutliers([(2.0,2.1),(2.1,2.0),(2.0,2.0),(4.0,4.0),(4.1,4.2),(4.2,4.1),(3.1,2.9),(3.0,3.0)], 2, 1.0))
[6, 7]
Avatar of gelonida
Flag of France image

Just to be sure:

does k=1 mean you compare v[n] with v[n-1] and v[n+1]
and k=2 mean you compare v[n] with v[n-2], v[n-1], v[n+1], v[n+2]

to attack this problem decompose it into simple steps:

1 function to calculate distance between two points
1 function / generator to return you the sliding window with values (or indices) to compare with

which verion of Python are you using?
Avatar of gelonida
Flag of France image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: gelonida (https:#a40953663)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer