KatInterview

Regional Weather Data: Metrics, Forward Selection, Online Slope

Machine LearningModel answer
MediumModel answerMachine Learningregressiontime-seriesfeature-selection

Last updated

Analyze multi-town daily temperature data: define volatility and similarity metrics, fit and validate a regression, run greedy town selection, and derive batch and streaming no-intercept slopes.

You have a table of daily temperature readings. Each row holds a date, the temperature in a large city (call it the target city), and the temperature in each of several surrounding towns on that same date.

Work through the following parts. For each, state your metric or method precisely and explain why you chose it.

  1. Which town swings the most? Pick a way to measure how much a town's temperature fluctuates and use it to name the most variable town.

  2. Which town looks most like the target city? Pick a similarity measure between a town's series and the target city's series, and use it to name the closest town.

  3. Predict the target city's temperature. Build a regression model that uses the towns' temperatures as inputs, and report its mean squared error (MSE). Describe how you split the data.

  4. Greedy forward selection. Given an integer k, start with no towns. At each step add the single town whose inclusion (together with those already chosen) lowers validation MSE the most. Return the k chosen towns and the final MSE.

  5. Regression through the origin. For one predictor x and a target y, fit y ≈ β·x with no intercept.

    • Give the batch solution for a full dataset.
    • Then handle a stream of (x, y) pairs arriving one at a time, updating β after each pair without revisiting earlier data.

Discuss pitfalls you would watch for, such as seasonality, leakage, and degenerate inputs.

Hints

Hint 1

Every town shares the same yearly warm-cold cycle. Think about what a metric on raw temperatures really measures, and what you could compute instead (day-to-day changes or deviations from a seasonal average).

Hint 2

Temperatures on neighboring days are almost duplicates. Ask how a random train/validation split would distort MSE, and what split respects time order.

Hint 3

For the no-intercept slope, set the derivative of the squared error to zero. The answer depends on only two running sums, which is exactly what makes a one-pair-at-a-time update cheap.