你可以在这里看到我的头像:http://bl.ocks.org/markarios/058f85800d598fc9f2b6
在检查还原时,我计算了每个设备类型的平均PPI,下面的代码产生了错误的结果。我唯一能想到的是,我有些需要如何使用ppi_device_sumi.key的索引,但我不知道如何引用它。
感谢提前给你时间!
// What's the average PPI per device?
write("");
write("Average PPI By Type");
for (var i = 0; i < type_device_count.length; i++) {
write(ppi_device_sum[i].key + "(s): " + ppi_device_sum[i].value/type_device_count[i].value);
};产品类型
片剂:7
桌面监视器:4
手提电脑:2台
智能手机:2
桌面:1
按设备类型分列的总PPI
平板电脑:1997年
智能手机: 770
桌面监视器: 444
笔记本电脑: 350台
桌面: 108台
按类型分列的平均PPI
片剂: 285.2857142857143 (正确)
智能手机: 192.5 (不正确,应该是385)
桌面监视器: 222 (不正确,应为111)
膝上型计算机: 175 (正确)
台式机: 108 (正确)
发布于 2014-06-18 13:37:46
在迭代数组之前,最好先按键对数组进行排序,以便它们的键按相同的顺序排列(JavaScript Array.prototype.sort()方法对此很好)。
如果您发现还原剂中的计算有任何问题,请提交一个关于Github的问题。目前它很生硬。在接下来的几周内,我将把它集成到一个更大的应用程序中,因此它将得到更多的使用和关注。
另一个注意事项:在您的要点中,您所做的事情让我认为您是在一个非常常见的误解下工作的,而这种误解是如何跨过滤器工作的。这不完全是直觉,但是
// calculate the number of device types
var type_count = type.group().reduceCount().size();
// how many of each device are there?
var type_device_count = type.group()
.reduceCount()
.top(type_count);是在做同样的事情
// Build the Crossfilter group.
var typeGroup = type.group(); // .reduceCount() is the default
// calculate the number of device types
var type_count = typeGroup.size(); // Now redundant
// how many of each device are there?
var type_device_count = typeGroup.top(Infinity); // Returns all groups后者是更好的方法,因为一旦您创建了一个Crossfilter组,当新数据被添加到Crossfilter和在其他维度上过滤时,这个组将被更新。因此,typeGroup.size()和typeGroup.top(无限)将返回不同的结果,因为交叉筛选器上的内容和过滤器会发生变化。保持这些组的更新使用资源,因此您希望创建尽可能少的维度和组来完成任务。
https://stackoverflow.com/questions/24275373
复制相似问题