explain
explain
Core explain() entry point: turn a fitted model into an LLM explanation.
Functions
| Name | Description |
|---|---|
| explain | Explain a statistical model’s output using an LLM. |
| suggest_code | Suggest code snippets to run next based on a model explanation. |
explain
explain.explain(
model_object,
client,
context=None,
language=None,
audience='novice',
verbosity='moderate',
style='markdown',
prompt_dir=None,
)Explain a statistical model’s output using an LLM.
Supported Models
This function supports fitted model objects from the following packages: * statsmodels: - OLS (Ordinary Least Squares regression) - GLM (Generalized Linear Models, e.g., Binomial, Gamma, NegBinomial) - MixedLM (Linear Mixed Effects models) - ARIMA / SARIMAX (Time Series models) - PHReg (Cox Proportional Hazards regression) * lifelines (optional): - CoxPHFitter (Cox Proportional Hazards survival models) - WeibullAFTFitter / LogNormalAFTFitter / LogLogisticAFTFitter (Parametric Accelerated Failure Time survival models) * pygam (optional): - GAM / LinearGAM / LogisticGAM / PoissonGAM (Generalized Additive Models)
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model_object | Any | A fitted statistical model object from a supported library (e.g., a results object from statsmodels). |
required |
| client | chatlas.Chat | A chatlas Chat client (e.g. from chatlas.ChatOpenAI() or chatlas.ChatAnthropic()). Never mutated by this function. |
required |
| context | str | Additional context about the data or research question to provide to the LLM. | None |
| language | str | The language the explanation should be written in (e.g. “Spanish”, “French”, “Mandarin Chinese”). If None (the default), no language constraint is added and the LLM will typically respond in the same language as the input/context or its default language. | None |
| audience | str | The target audience: one of “novice” (default), “student”, “researcher”, “manager”, or “domain_expert”. | 'novice' |
| verbosity | str | The desired level of detail: one of “brief”, “moderate” (default), or “detailed”. | 'moderate' |
| style | str | The output format style: one of “markdown” (default), “html”, “json”, “text”, or “latex”. | 'markdown' |
| prompt_dir | str | Custom prompts directory path to override package prompts. | None |
Returns
| Name | Type | Description |
|---|---|---|
| dict | A dictionary with keys: text, model_type, audience, verbosity, style. |
suggest_code
explain.suggest_code(explanation)Suggest code snippets to run next based on a model explanation.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| explanation | dict | The dictionary returned by explain(). |
required |
Returns
| Name | Type | Description |
|---|---|---|
| str | A formatted string of suggested Python diagnostics code. |