问题
I use dc.js for analyzing results of a classification algorithm and would like to filter on the confidence (additional metrics like precision, recall and f-measure are calculated on the whole filtered dataset).
Example: https://jsfiddle.net/bse7rfdy/6/
var conf = dc.barChart('#conf');
conf
.dimension(ConfidenceDimension)
.group(ConfidenceGroup)
.x(d3.scaleLinear().domain([0.0,1.05]))
.xAxisLabel("confidence")
.xUnits(function(){return 20;})
.yAxisLabel("");
Since the false negatives always have a confidence of 0.0 they will be filtered when the confidence bar chart is used to select a confidence range greater than 0.0.
Thus I want to achieve a filtering on confidence only when the "EvaluationResult" is not "false negative". I also don't want to show the false negatives in the confidence bar chart but in the pie chart (thus they should remain the the crossfilter dataset). I know that I can remove the 0.0 bar by using a fake group but when I filter on the confidence bar chart the fiter is applied and the "false negative" are removed (e.g. selecting a range from 0.5 to 0.6).
Actually I need to modify the filter in a way that the confidence range (selected by the user) is applied only if "EvaluationResult" !== "false negative".
Is that possible?
回答1:
Thanks for the fiddle, that helps so much for answering questions.
You can do this by specifying a filterHandler for the chart.
The results are a little weird, because the pie chart will always show the same number of false negatives, while the other slices change size.
function filter_range_ignore_zeroes(dimension, filters) {
if(filters.length === 0) {
dimension.filter(null);
return
}
const filter = filters[0],
rf = dc.filters.RangedFilter(filter[0],filter[1]);
dimension.filterFunction(k => k===0 || rf.isFiltered(k));
return filters;
}
conf.filterHandler(filter_range_ignore_zeroes);
The handler has two cases: if there's no filter active, it resets the dimension filter.
Otherwise, it installs a filter function on the dimension which accepts zeroes but delegates to the default dc.filters.RangedFilter behavior otherwise.
Fork of your fiddle.
[You're not binning the confidence in this fiddle, so the bars overlap and go to 1.0, but I figure you have that working in your actual dashboard.]
来源:https://stackoverflow.com/questions/57575866/ignore-subset-of-data-when-filtering