Skip to content

regression

AeroViz.plot.regression.linear_regression

linear_regression(df: DataFrame, x: str | list[str], y: str | list[str], labels: str | list[str] = None, ax: Axes | None = None, diagonal=False, positive: bool = True, fit_intercept: bool = True, **kwargs) -> tuple[Figure, Axes]

Create a scatter plot with regression lines for the given data.

Parameters:

Name Type Description Default
df DataFrame

Input DataFrame containing the data.

required
x str or list of str

Column name(s) for the x-axis variable(s). If a list, only the first element is used.

required
y str or list of str

Column name(s) for the y-axis variable(s).

required
labels str or list of str

Labels for the y-axis variable(s). If None, column names are used as labels. Default is None.

None
ax Axes

Matplotlib Axes object to use for the plot. If None, a new subplot is created. Default is None.

None
diagonal bool

If True, a diagonal line (1:1 line) is added to the plot. Default is False.

False
positive bool

Whether to constrain the regression coefficients to be positive. Default is True.

True
fit_intercept bool

Whether to calculate the intercept for this model. Default is True.

True
**kwargs

Additional keyword arguments for plot customization.

{}

Returns:

Name Type Description
fig Figure

The matplotlib Figure object.

ax Axes

The matplotlib Axes object with the scatter plot.

Notes
  • The function creates a scatter plot with optional regression lines.
  • The regression line is fitted for each y variable.
  • Customization options are provided via **kwargs.
Example

linear_regression(df, x='X', y=['Y1', 'Y2'], labels=['Label1', 'Label2'], ... diagonal=True, xlim=(0, 10), ylim=(0, 20), ... xlabel="X-axis", ylabel="Y-axis", title="Scatter Plot with Regressions")

AeroViz.plot.regression.multiple_linear_regression

multiple_linear_regression(df: DataFrame, x: str | list[str], y: str | list[str], labels: str | list[str] = None, ax: Axes | None = None, diagonal=False, positive: bool = True, fit_intercept: bool = True, **kwargs) -> tuple[Figure, Axes]

Perform multiple linear regression analysis and plot the results.

Parameters:

Name Type Description Default
df DataFrame

Input DataFrame containing the data.

required
x str or list of str

Column name(s) for the independent variable(s). Can be a single string or a list of strings.

required
y str or list of str

Column name(s) for the dependent variable(s). Can be a single string or a list of strings.

required
labels str or list of str

Labels for the dependent variable(s). If None, column names are used as labels. Default is None.

None
ax Axes

Matplotlib Axes object to use for the plot. If None, a new subplot is created. Default is None.

None
diagonal bool

Whether to include a diagonal line (1:1 line) in the plot. Default is False.

False
positive bool

Whether to constrain the regression coefficients to be positive. Default is True.

True
fit_intercept bool

Whether to calculate the intercept for this model. Default is True.

True
**kwargs

Additional keyword arguments for plot customization.

{}

Returns:

Type Description
tuple[Figure, Axes]

The Figure and Axes containing the regression plot.

Notes

This function performs multiple linear regression analysis using the input DataFrame. It supports multiple independent variables and can plot the regression results.

Example

multiple_linear_regression(df, x=['X1', 'X2'], y='Y', labels=['Y1', 'Y2'], ... diagonal=True, fit_intercept=True, ... xlabel="X-axis", ylabel="Y-axis", title="Multiple Linear Regression Plot")