Group Gaps
df has columns team (a name) and score. Fit score ~ C(team) with a statsmodels formula: the intercept becomes the mean of the alphabetically first team and every other team gets its gap to it. Return the parameters as a dict (the keys are the names statsmodels gives them).
Example 1
df {"team":["a","a","b","b","c","c"],"score":[1,3,6,8,2,2]}
returns {"Intercept":2.0,"C(team)[T.b]":5.0,"C(team)[T.c]":0.0}
Team a averages 2. Team b averages 7, which is 5 more, and team c averages the same as a.
Constraints
- 2 to 4 teams, each with at least 2 rows
len(df) <= 40
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More statsmodels problems
- Is the Share DifferentEasy
- Is the Slope RealEasy
- Prices for New RowsEasy
- Range for the SlopeEasy
- Two CausesEasy
- Better of Two ModelsMedium
- Chance of YesMedium
- Does One Change the OtherMedium