简体   繁体   English

Vega-Lite:如何按字段求和并将其用作类别

[英]Vega-Lite: How to sum by a field and use it as a category

So my situation is the following.所以我的情况如下。 I have 60.000 images, and they were trained using 4 models.我有 60.000 张图像,它们使用 4 个模型进行了训练。 Each model tries to predict what is in the image, so I end up with a dataset containing where each image shows up 4 times.每个 model 都试图预测图像中的内容,因此我最终得到了一个数据集,其中包含每个图像出现 4 次的位置。 Now, what I'd like to group each image according to how many models were able to get it correct.现在,我想根据有多少模型能够正确地对每个图像进行分组。 In other words, one image might have been predicted correctly in all 4 models, and another incorrectly in all 4, so the first should be in category 4 and the second in category 1.换句话说,一个图像可能在所有 4 个模型中都被正确预测,而另一个在所有 4 个模型中都被错误地预测,所以第一个应该在类别 4 中,第二个应该在类别 1 中。

How can I do this using Vega-Lite (I know I could preprocess the data, but I'd like to do it directly with Vega-Lite).我如何使用 Vega-Lite 做到这一点(我知道我可以预处理数据,但我想直接用 Vega-Lite 来做)。 I've tried the following, but without success:我尝试了以下方法,但没有成功:

vl.markPoint()
    .data(data)
    .transform(
      vl.groupby('image_id'),
      vl.joinaggregate( [{
      "op": "sum",
      "field": "acc",
      "as": "totalacc"}]),
      vl.calculate("datum.totalacc").as('total')
    )
    .encode(
      vl.y().sum('acc'),
      vl.x().fieldQ('total'),
      vl.detail().fieldQ('image_id')
    ).render();

vl.groupby() by itself doesn't do anything to the data. vl.groupby()本身不会对数据做任何事情。 I suspect what you probably want for your transforms is something like this:我怀疑您可能想要的转换是这样的:

    .transform(
      vl.groupby('image_id')
        .joinaggregate([{
          "op": "sum",
          "field": "acc",
          "as": "totalacc"
        }]),
      vl.calculate("datum.totalacc").as('total')
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM