GoodnessOfFitCharts
GoodnessOfFitCharts
¶
Bases: SingleChart
Visualizes the evolution of goodness-of-fit metrics across the steps of a recursive parameter elimination.
The GoodnessOfFitCharts class takes the goodness-of-fit table
collected during LinearModel.recursive_elimination and plots
R², adjusted R², the p-value of the least significant term and the
min-max normalized Akaike information criterion (AIC) against the
elimination step. A dashed line marks the significance level used
to decide whether a term should be eliminated, and a shaded area
highlights the elimination steps at which the model was
heterarchical, i.e. not hierarchical.
Once a preferred epoch has been identified visually, use
formula_at_epoch or refit_at_epoch to extract the formula used
at that step and refit the underlying LinearModel with it.
| PARAMETER | DESCRIPTION |
|---|---|
df_gof
|
The goodness-of-fit table collected during recursive
elimination, i.e. the concatenated result of
TYPE:
|
linear_model
|
The linear regression model the given
TYPE:
|
stretch_figsize
|
If True, the height and width of the figure are stretched based on the number rows and columns in the axes grid. If a float is provided, the figure size is stretched by the given factor. If a tuple of two floats is provided, the figure size is stretched by the given factors for the x and y axis, respectively. by default False.
TYPE:
|
Examples:
import pandas as pd
import daspi as dsp
df = dsp.load_dataset('painkillers-dissolution')
lm = dsp.LinearModel(
source=df,
target='dissolution',
factors=['employee', 'stirrer', 'brand', 'catalyst', 'water'],
covariates=['temperature', 'preparation'],
order=2)
df_gof = pd.concat(lm.recursive_elimination())
chart = dsp.GoodnessOfFitCharts(df_gof, lm).plot().stripes().label(info=True)

Once a good epoch has been picked by eye, e.g. epoch 5, refit the model with the formula recorded at that step:
lm = linear_model
instance-attribute
¶
The linear regression model the goodness-of-fit table was generated from.
df_gof = df_gof.sort_values(ANOVA.EPOCH).reset_index(drop=True)
instance-attribute
¶
The goodness-of-fit table used to build this chart.
metric_labels = {ANOVA.R2: '$R^2$', ANOVA.R2_ADJ: '$R^2_{adj}$', ANOVA.P_LEAST: '$p_{least}$', self._AIC_NORM: '$AIC_{norm}$'}
instance-attribute
¶
Mapping of the goodness-of-fit column names to the mathtext label used for them in the legend.
plot
¶
Plot each goodness-of-fit metric as a line against the elimination step.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |
stripes
¶
Adds a dashed line at the significance level used for the elimination and a shaded area marking the elimination steps at which the model was not hierarchical.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |
formula_at_epoch
¶
Get the model formula recorded at the given elimination step.
| PARAMETER | DESCRIPTION |
|---|---|
epoch
|
The elimination step whose formula should be extracted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The model formula used at the given |
refit_at_epoch
¶
Refit the underlying LinearModel with the formula recorded
at the given elimination step.
Use this once you have picked a preferred epoch by inspecting
the chart produced by plot(), e.g. where the significance
threshold and the hierarchy of the model satisfy you best.
| PARAMETER | DESCRIPTION |
|---|---|
epoch
|
The elimination step whose formula should be used to refit the model.
TYPE:
|
**kwds
|
Additional keyword arguments for
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
LinearModel
|
The |
label
¶
Adds titles and labels to the chart generated by the
plot() method.
| PARAMETER | DESCRIPTION |
|---|---|
info
|
If
TYPE:
|
**kwds
|
Additional keyword arguments to be passed to the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |