Ignore subset of data when filtering

牧云@^-^@ 提交于 2019-12-24 03:51:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!