gpt4 book ai didi

hadoop - Apache Pig 分位数分组

转载 作者:可可西里 更新时间:2023-11-01 16:14:04 24 4
gpt4 key购买 nike

我正在努力寻找解决 Pig 分组问题的方法。目前我有一个看起来像的数据集;

Group | Height | Weight
A | 96.5 | 110.2
B | 88.2 | 122.5
A | 94.1 | 100.8
B | 84.1 | 115.6

我正在使用 DataFu 库中的 StreamingQuantile 方法来计算高度变量的分位数(第 25、50... eclipse 刻)。目前它有效,但我还需要计算每个组的 AVG 权重 + 它们的分位数;所以它看起来像这样;

A | Quantile1 | 88.5 (height)  | 134.4 (avg weight)
A | Quantile2 | 125.3 (height) | 156.2 (avg weight)
etc.....
B | Quantile4 | 144.3 (height) | 134.2 (avg weight)

作为引用,这是用于计算分位数的简单 Pig;

REGISTER /usr/lib/datafu-1.2.0.jar;
define Quantile datafu.pig.stats.StreamingQuantile('0.0','0.25','0.5','0.75','1.0');
A = load 'mydata';
Group_A = GROUP A BY $0;
Quant = FOREACH GROUP_A GENERATE group,Quantile(A.$1);

无论如何我也可以计算每个分位数和组的 2 美元的平均值吗?

最佳答案

我给列命名是为了避免混淆。

REGISTER /usr/lib/datafu-1.2.0.jar;
define Quantile datafu.pig.stats.StreamingQuantile('0.0','0.25','0.5','0.75','1.0');
A = load 'mydata' using PigStorage('|') as (grouping:chararray, height:double, weight:double);
Group_A = GROUP A BY grouping;
Quant = FOREACH GROUP_A GENERATE group, Quantile(A.height) as q;
joined = join Quant by group, A by grouping;
grouped = group joined by (grouping, q)
average = foreach grouped generate group, AVG(joined.weight);

关于hadoop - Apache Pig 分位数分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25789961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com