You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let discr = require("statsbreaks")
let data = [1, 1, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 'foo', -Infinity, NaN]
let series = new discr.JenksClassifier(data, 2);
let bks = series.classify(3);
let count = series.countByClass();
I think count should be [8, 5, 2] (as if we used [1, 1, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8] as input array) instead of [9, 5, 2, NaN].
The breaks returned are correct (because the input array is filtered in the inner classification function) but in Classifier classes we store the input array before it is filtered :
A quick fix is simply to store the filtered input array in the line of code shown below (but we'll be redoing this filtering for nothing in the internal classification function).
A better fix might be to avoid doing this filtering twice (and to avoid creating too many new arrays, since doing array.filter(/* some code */).map(/* some code */) creates two new arrays). However, in most cases this shouldn't make any noticeable difference to performance.
The text was updated successfully, but these errors were encountered:
mthh
changed the title
Count by class is wrong when input array contains non finite number
Count by class is wrong when input array contains values that are non number / non finite number
Apr 29, 2024
mthh
changed the title
Count by class is wrong when input array contains values that are non number / non finite number
Count by class is wrong when input array contains values that are not number / non finite number
Apr 29, 2024
Consider the following code:
I think
count
should be[8, 5, 2]
(as if we used[1, 1, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8]
as input array) instead of[9, 5, 2, NaN]
.The breaks returned are correct (because the input array is filtered in the inner classification function) but in Classifier classes we store the input array before it is filtered :
statsbreaks/src/classifier.js
Line 25 in c016c68
A quick fix is simply to store the filtered input array in the line of code shown below (but we'll be redoing this filtering for nothing in the internal classification function).
A better fix might be to avoid doing this filtering twice (and to avoid creating too many new arrays, since doing
array.filter(/* some code */).map(/* some code */)
creates two new arrays). However, in most cases this shouldn't make any noticeable difference to performance.The text was updated successfully, but these errors were encountered: