← 返回 stripe 的题目列表Multi-task regression with opposite-signed targets: normalize and train jointly
类型:online_judge
Question: Multi-task regression with two heads; one target is negative and the other is positive — normalize and train jointly
You are given training and test data. Each example has a $d$-dimensional feature vector $x$ and two regression targets:
Task A target $y_A$ is negative (e.g., in $[-10^6, -1]$)
Task B target $y_B$ is positive (e.g., in $[10, 10^3]$)
Because the two tasks have opposite signs and very different magnitudes, naive joint training will be dominated by the larger-scale target.
Implement a joint regression model with the following requirements:
Flip the sign of task A during training: $y'_A = -y_A$ so it becomes positive.
Normalize/standardize the two targets separately (e.g., z-score or min-max) so their losses are on comparable scales.
Train a model with shared parameters and two output heads (or an equivalent parameterization). Optimize:
$$L = \text{MSE}(\hat{y}_A, y_A) + \text{MSE}(\hat{y}_B, y_B)$$
You may compute the loss in the normalized space, but your final printed predictions must be in the original target space:
$\hat{y}_A$ must be negative (undo the sign flip)
$\hat{y}_B$ must be positive
Input (stdin)
n_train n_test d
x11 x12 ... x1d yA1 yB1
...
xn1 xn2 ... xnd yAn yBn
x'11 x'12 ... x'1d
...
x'm1 x'm2 ... x'md
Output (stdout)
For each test sample, print one line:
yA_pred yB_pred
Constraints
$1 \le n_{train} \le 2000$
$1 \le n_{test} \le 2000$
$1 \le d \le 50$
All values are floats
Notes
You may implement linear regression with gradient descent (optional L2 regularization). Do not use off-the-shelf training libraries (sklearn/pytorch/etc.).
The focus is on correct sign handling, per-task normalization, and correct de-normalization of predictions.
Example
Input
3 2 2
1 0 -10 100
0 1 -20 200
1 1 -30 150
1 0
0 1
Output
-10.0 100.0
-20.0 200.0