How would you group/cluster these three areas in arrays in python?

后端 未结 5 939
挽巷
挽巷 2021-02-01 07:42

So you have an array

1
2
3
60
70
80
100
220
230
250

For a better understanding:

\"

5条回答
  •  名媛妹妹
    2021-02-01 08:05

    I assume you want a pretty-good-but-simple algorithim here.

    If you know you want N clusters, then you can take the differences (deltas) between consecutive members of the (sorted) input list. E.g. in numpy:

     deltas = diff( sorted(input) )
    

    Then you can place your cuttoffs where you find the N-2 biggest differences.

    Things are trickier if you don't know what N is. Here you might place the cuttoffs whenever you see a delta greater than a certain size. This will then be a hand-tuned parameter, which is not great, but might be good enough for you.

提交回复
热议问题