Problem · Math

Town Temperature Regression Analysis

HardCitadel logoCitadelFULLTIMEPHONE SCREEN

Problem statement

You are given a temperatures table containing daily temperatures for NYC and six predictor towns named Town1 through Town6. Produce exactly six analysis rows.

  1. Find the town with the largest population standard deviation of temperature.
  2. Take the median NYC temperature among rows where Town2 is between 90 and 100, inclusive. Use 0 when there are no such rows, then round to the nearest integer.
  3. For each town independently, fit ordinary least squares with an intercept to predict NYC from that town. Sum the absolute values of the six slope coefficients, excluding intercepts, then round to the nearest integer.
  4. Find the single town whose intercept-based model has the smallest training mean squared error.
  5. Find the pair of towns whose joint intercept-based model has the smallest training mean squared error.
  6. 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 town 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 shown below. 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 MSE.

Table schema

Pandas

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.

ColumnTypeNullableDescription
day_idPKIntegerNo
NYCDecimalNo
Town1DecimalNo
Town2DecimalNo
Town3DecimalNo
Town4DecimalNo
Town5DecimalNo
Town6DecimalNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
metricTextNo
townsTextYes
valueDecimalYes

Row order: must match exactly. Numeric tolerance: 0.000001.

Constraints

  • The table has 8 to 1000 rows.
  • day_id values are distinct; input row order does not affect the result.
  • All temperatures are finite decimals with absolute value at most 10^6.
  • The 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 or relative tolerance 10^-6.

More Citadel problems