Top of the Curve
df has columns x and y, and y follows a curve that bends once: up then down, or down then up. Fit y on x and x squared with a statsmodels formula, and return the x where the fitted curve turns around.
Example 1
df {"x":[0,1,2,3,4,5,6],"y":[0,5,8,9,8,5,0]}
returns 3.0
The points follow 9 - (x - 3) squared, which peaks at x = 3.
Constraints
6 <= len(df) <= 40- The curve really bends
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More statsmodels problems
- Trust Some Points MoreMedium
- Uneven SpreadMedium
- Do the Effects CombineHard
- Drop the Weak OnesHard
- Effect of the ProgramHard
- Enough PeopleHard
- Honest ErrorHard
- Next Three ValuesHard