Daily Temperature By Town
Problem statement
For this exercise, assume the input contains daily temperatures for NYC and six predictor towns named Town1 through Town6. Produce exactly six analysis rows.
- Among
NYCand all six towns, find the place with the largest population standard deviation of temperature. - Take the median
NYCtemperature among rows whereTown2is between90and100, inclusive. Use0when there are no such rows, then round to the nearest integer. - For each town independently, fit ordinary least squares with an intercept to predict
NYCfrom that town. Sum the absolute values of the six slope coefficients, excluding intercepts, then round to the nearest integer. - Find the single town whose intercept-based model has the smallest training mean squared error.
- Find the pair of towns whose joint intercept-based model has the smallest training mean squared error.
- Select five towns by forward greedy selection. Starting with no towns, repeatedly add the unused town that gives the smallest training mean squared error when fit jointly with the already selected towns and an intercept.
For every exact score tie, choose the lexicographically smaller place name or comma-joined town list. Round halfway values away from zero. All supplied predictor matrices have a unique least-squares solution.
Return columns metric, towns, and value in the exact row order above. Use null for towns on the two numeric-only rows and for value on the maximum-standard-deviation row. Pair names are comma-joined in lexicographic order; the five-town list is comma-joined in greedy selection order. The value for the last three selection rows is that model's training mean squared error.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
temperatures
One row per observed day, with NYC as the regression target and six town predictors.
| Column | Type | Nullable | Description |
|---|---|---|---|
| day_idPK | Integer | No | — |
| NYC | Decimal | No | — |
| Town1 | Decimal | No | — |
| Town2 | Decimal | No | — |
| Town3 | Decimal | No | — |
| Town4 | Decimal | No | — |
| Town5 | Decimal | No | — |
| Town6 | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| metric | Text | No | — |
| towns | Text | Yes | — |
| value | Decimal | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.000001.
Constraints
- The
temperaturestable has between8and1000rows. day_idvalues are distinct; input row order does not affect the result.- Every temperature is a finite decimal with absolute value at most
10^6. NYCand all six town columns contain no missing values.- Every tested predictor matrix, including the intercept column, has a unique least-squares solution.
- Decimal results are compared with absolute tolerance
10^-6.