Skip to content

ResidualsCharts

ResidualsCharts

Bases: JointChart

Provides a set of charts for visualizing the residuals of a linear regression model.

The ResidualsCharts class takes a LinearModel instance and generates a set of four charts: - Probability plot of the residuals - Gaussian kernel density estimate of the residuals - Scatter plot of the predicted values vs. the observed values - Line plot of the predicted values vs. the observed values

The plot() method generates the charts, and the label() method adds titles and labels to the charts.

PARAMETER DESCRIPTION
linear_model

The linear regression model whose residuals will be visualized.

TYPE: LinearModel

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: bool | float | tuple[float, float] DEFAULT: False

Examples:

import daspi as dsp
import pandas as pd

df = dsp.load_dataset('painkillers-dissolution')
model = dsp.LinearModel(
    source=df,
    target='dissolution',
    features=['employee', 'stirrer', 'brand', 'catalyst', 'water'],
    covariates=['temperature', 'preparation'],
    order=2)
df_gof = pd.concat(model.recursive_elimination())
dsp.ResidualsCharts(model).plot().stripes().label(info=True)

ResidualsChartsDocstringExample

lm = linear_model instance-attribute

The linear regression model whose residuals are visualized.

plot

Generates a set of four charts for visualizing the residuals of a linear regression model: - Probability plot of the residuals - Gaussian kernel density estimate of the residuals - Scatter plot of the predicted values vs. the observed values - Line plot of the predicted values vs. the observed values

RETURNS DESCRIPTION
Self

The ResidualsCharts instance, for method chaining.

TYPE:

stripes

Adds a line at position 0 for each subplot except for the probability plot. This line represents the fit of the model.

label

Adds titles and labels to the charts generated by the plot() method.

PARAMETER DESCRIPTION
info

If True, the method will add an informative subtitle to the chart. If a string is provided, it will be used as the subtitle, by default False.

TYPE: bool | str DEFAULT: False

**kwds

Additional keyword arguments to be passed to the label() method of the JointChart instance.

DEFAULT: {}

RETURNS DESCRIPTION
Self

The ResidualsCharts instance, for method chaining.