← 返回 twosigma 的题目列表QR OA — Efficient Univariate OLS Regression
类型:qbank
Compute no-intercept univariate OLS slopes, then update the slope over streaming or batched data using maintained sufficient statistics rather than refitting from scratch.
Requirements
Given paired observations (x_i, y_i), compute the slope of a univariate ordinary least-squares regression without an intercept.
Reported variants include:
Given two dataframes, pair columns and compute a regression coefficient for each column pair.
Given a batch of (x, y) points, return the no-intercept OLS slope.
Follow-up: data arrives in batches. After each new batch, output the current slope over all data seen so far without recomputing from the beginning.
Notes
The no-intercept slope is driven by maintained sums: numerator sum(x_i * y_i) and denominator sum(x_i^2).
The streaming version should update the numerator, denominator, and count or validity metadata per batch, then emit the current ratio.
Candidates repeatedly identify this as the third QR OA task and the one that punishes weak formula recall or poor time allocation.
Preparation
Derive the no-intercept OLS slope by differentiating squared error with respect to beta.
Write a small OnlineOLS object with update(batch) and slope() methods.
Practice dataframe column-pair iteration and be explicit about NaNs, zero denominator, and shape mismatch.