← 返回 citadel 的题目列表Online Batched No-Intercept Regression
类型:online_judge
You are given two aligned asset-return data sets, dfx and dfy, with the same number of rows and the same corresponding K columns. For each column j, use column j of dfx as x_j and column j of dfy as y_j, and fit a univariate regression without an intercept:
[ y_j = \beta_j x_j ]
Part 1
Implement:
no_intercept_betas(dfx, dfy) -> list[float]
Return, for every column:
[ \beta_j = \frac{\sum_i x_{ij} y_{ij}}{\sum_i x_{ij}^2} ]
Part 2
Data arrives in M batches. Batch b is (dfx_batches[b], dfy_batches[b]); every batch has K columns, though batch row counts may differ.
Implement:
cumulative_no_intercept_betas(dfx_batches, dfy_batches) -> list[list[float]]
Output M vectors. Output b must contain the K betas fitted using all data from batches 0 through b.
Do not concatenate or rescan all historical DataFrames at each step. Maintain per-column cumulative sum_xy and sum_x2, updating them with each incoming batch. Assume each cumulative denominator is positive.
Example
Input
dfx=[[1],[2]], dfy=[[2],[4]]
Output
[2.0]