feat: add diagnose_residuals_tool for agentic residual diagnostics#402
Open
DEEP-600 wants to merge 1 commit intosktime:mainfrom
Open
feat: add diagnose_residuals_tool for agentic residual diagnostics#402DEEP-600 wants to merge 1 commit intosktime:mainfrom
DEEP-600 wants to merge 1 commit intosktime:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #400.
What and why
Reading through the existing tool surface and #386, I noticed the
agentic loop has no feedback mechanism after a poor evaluation score.
The agent gets MAPE = 25% and has nothing to work with beyond trying
another model.
Human forecasters look at residuals at this point — ACF for missed
seasonality, normality checks, bias direction. Agents can't look at
plots, so this tool runs those same checks and returns structured text
they can reason over.
What's in this PR
src/sktime_mcp/tools/diagnose.py— the new tool__init__.pyandserver.pyupdated to expose ittests/test_diagnose.py— three test casesHow it works
Takes an
estimator_handleanddataset, reloads the data the sameway
evaluate.pydoes, pulls the fitted instance from_handle_manager, and runs three tests on the residuals:No new dependencies —
statsmodelsandscipyare already inpyproject.toml.Example output
{ "success": true, "diagnostics": { "bias": {"mean_error": -4.2, "status": "consistently over-forecasting"}, "autocorrelation": {"ljung_box_passed": false, "significant_lags": [12, 24]}, "normality": {"shapiro_passed": false, "p_value": 0.01} }, "llm_hint": "Residuals show significant autocorrelation at lags [12, 24]. This may indicate missed annual seasonality. Consider switching to SARIMA or adding a Deseasonalizer pipeline." }A couple of things I'd like feedback on
predict_residuals(y)as primary with a manual fallback forcomplex pipelines — is that the right call or overkill?
follow-up if that's useful.