← 返回 citadel 的题目列表Town Temperature Regression Analysis
类型:online_judge
Given a pandas.DataFrame df, each column contains daily temperatures over the same N consecutive days for either a town or New York City. The NYC column is named NYC; there are P town columns besides it. Assume all values are numeric and contain no missing values.
Implement:
q1_q5(df) -> list
q6(df) -> list
Part One: q1_q5(df)
Return [q1, q2, q3, q4, q5]:
q1: name of the location with the largest population standard deviation of temperature. Break ties lexicographically.
q2: among rows where 90 <= Town2 <= 100, return the median NYC temperature rounded with Python round; return None if no row qualifies.
q3: for each town, fit NYC = alpha + beta * town_temperature with an intercept. Return the rounded integer value of the sum of abs(beta) over all towns.
q4: fit an intercept linear regression using each town alone and return the town with the smallest training MSE. Break ties lexicographically.
q5: fit intercept linear regressions for every pair of towns and return the pair with the smallest training MSE as a lexicographically ordered tuple. Break ties lexicographically.
Part Two: q6(df)
Choose exactly five towns using forward greedy feature selection. Start with no selected towns. At each step, add the unselected town that yields the smallest training MSE for an intercept linear regression predicting NYC. Break ties lexicographically. Return the five selected town names in selection order.
Do not use ML training libraries such as sklearn. NumPy, pandas, and numpy.linalg.lstsq are allowed. Assume N >= 2 and P >= 5.
Example
Input
df = DataFrame with columns NYC, Town1, Town2, Town3, Town4, Town5 and 10 aligned daily rows
Output
q1_q5(df) returns [location_name, integer_or_None, integer, town_name, (town_a, town_b)]; q6(df) returns five town names.