[Feature Request]: [Python] Add Variance, StandardDeviation, Covariance, and LinearRegression to apache_beam.transforms.combiners
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by reading the Python SDK's apache_beam.transforms.combiners implementation and its existing combiner tests. The issue specifies four statistical combiners, stable distributed accumulator merging, multiple input shapes, and a structured regression result, so scope the work and tests around those requirements. Done means the new combiners handle the requested inputs and produce the stated statistics across distributed merges.
由索引模型根据 Issue 内容生成。
描述
What would you like to happen?
Currently, apache_beam.transforms.combiners provides standard aggregation transforms such as Count, Mean, Min, Max, Top, and Sample. However, common statistical and bivariate regression aggregations are missing from the Python SDK:
Variance(sample and population)StandardDeviation(sample and population)Covariance(sample and population for (x, y) pairs or structured records)LinearRegression(ordinary least squares slope, intercept, r, r2, and means)
While users can compute sample means with combiners.Mean.Globally(), calculating variance, standard deviation, covariance, or linear regression currently requires writing custom multi-pass accumulators or pulling in NumPy/SciPy inside custom CombineFns, which can be tricky to make numerically stable across distributed worker combines.
We propose adding first-class, numerically stable combiners in apache_beam.transforms.combiners:
import apache_beam as beam
from apache_beam.transforms import combiners
# 1. Variance & Standard Deviation
with beam.Pipeline() as p:
numbers = p | beam.Create([10.0, 20.0, 30.0, 40.0, 50.0])
sample_var = numbers | 'SampleVar' >> combiners.Variance.Globally()
pop_stddev = numbers | 'PopStdDev' >> combiners.StandardDeviation.Globally(sample=False)
# 2. Covariance
with beam.Pipeline() as p:
points = p | beam.Create([(1.0, 2.0), (2.0, 4.0), (3.0, 5.0), (4.0, 7.0)])
cov = points | combiners.Covariance.Globally()
# 3. Ordinary Least Squares Linear Regression
with beam.Pipeline() as p:
ad_data = p | beam.Create([
{'spend': 10, 'revenue': 25.0},
{'spend': 20, 'revenue': 41.0},
{'spend': 30, 'revenue': 62.0},
])
model = ad_data | combiners.LinearRegression.Globally(x='spend', y='revenue')
# Emits RegressionResult(count=3, slope=1.85, intercept=5.67, r=0.998, r2=0.997, mean_x=20.0, mean_y=42.67)
Key Technical Details
- Numerical Stability: Uses single-pass, numerically stable Welford updating equations for both variance and bivariate cross-products, and Chan et al. pairwise merging for distributed accumulator merges (
merge_accumulators). - Flexible Input Shapes:
VarianceandStandardDeviationaccept numeric types (int,float,np.number).CovarianceandLinearRegressionaccept 2-tuples/sequences(x, y)or key-value/dict mappings withx='col_x', y='col_y'.
- Structured Output:
LinearRegressionreturns a typedNamedTuple(RegressionResult) containing(count, slope, intercept, r, r2, mean_x, mean_y). - Runner & Streaming Parity: Fully pure Python, runner-agnostic, zero extra dependencies, and works out-of-the-box in batch, streaming, DirectRunner, Prism, and Dataflow.
Issue Priority
Priority: 2 (default / most feature requests should be filed as P2)
Issue Components
- Component: Python SDK
- Component: beam-core
- 主要语言
- Java
- 星标
- 8.7k
- 派生
- 4.8k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 371
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/beam 的其他 Issue
-
awaiting triage bug P3
难度 1/5 1 小时以内 新手友好度 67/100
维护者通常 1 天内回复
-
[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal places可能已有人在做 @Abhi2939 于 1 天前认领。 未关闭io P2 python yaml
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
apache/beam#39624 · 2 个 reaction ·
维护者通常 1 天内回复
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size可能已有人在做 @1fanwang 于 78 天前认领。 未关闭bug io P3 pinned pubsub
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
build P3 sub-task
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
SasanLabs/VulnerableApp#912 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
desktop edt not responding
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
datafusion-contrib/StreamFusion#653 ·
维护者通常 1 天内回复
-
[Bug] Absolute row/column index 0 is ignored for images, hyperlinks and comments可能已有人在做 @fanOfSunny 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复