Regression Plots#
- class PlotPredVsObs(method_name: str, description: str, plot_settings)[source]#
Bases:
PlotEvaluatorPlot the predicted vs. observed values for a regression model.
This evaluator creates scatter plots comparing predicted values against observed values for regression models. The plot includes a diagonal reference line (y=x) to help assess model performance, where points closer to this line indicate better predictions.
- Attributes:
- namestr
The name of the evaluator, set to ‘pred_vs_obs’
- generate_plot_data(prediction: Series, y_true: Series) Tuple[DataFrame, float][source]#
Calculate the plot data for the predicted vs. observed values.
Prepares the data needed for creating predicted vs observed plots by combining predictions and true values into a DataFrame and calculating the maximum range for consistent axis scaling.
- Parameters:
- predictionpd.Series
The predicted values from the model
- y_truepd.Series
The true target values
- Returns:
- Tuple[pd.DataFrame, float]
A tuple containing: - DataFrame with ‘Observed’ and ‘Predicted’ columns - Maximum range value for consistent axis scaling
- plot(model: BaseEstimator, X: DataFrame, y: Series, filename: str) None[source]#
Plot the predicted vs. observed values for a regression model.
Creates a scatter plot comparing predicted values against observed values with a diagonal reference line. Points closer to the diagonal line indicate better model performance.
- Parameters:
- modelbase.BaseEstimator
The trained regression model to evaluate
- Xpd.DataFrame
The input features used for prediction
- ypd.Series
The true target values to compare against predictions
- filenamestr
The filename to save the plot to
- Returns:
- None
The plot is saved to the specified filename
- class PlotResiduals(method_name: str, description: str, plot_settings)[source]#
Bases:
PlotEvaluatorPlot the residuals of a regression model.
This evaluator creates residual plots showing the difference between observed and predicted values. Residual plots help identify patterns in model errors, such as heteroscedasticity or non-linear relationships that the model failed to capture.
- Attributes:
- namestr
The name of the evaluator, set to ‘residuals’
- generate_plot_data(predictions: Series, y: Series) DataFrame[source]#
Calculate the residuals (observed - predicted).
Computes residuals by subtracting predicted values from observed values and organizes the data for residual plotting.
- Parameters:
- predictionspd.Series
The predicted values from the model
- ypd.Series
The true target values
- Returns:
- pd.DataFrame
DataFrame containing ‘Observed’ and ‘Residual (Observed - Predicted)’ columns
- plot(model: BaseEstimator, X: DataFrame, y: Series, filename: str, add_fit_line: bool = False) None[source]#
Plot the residuals of a regression model.
Creates a scatter plot of residuals (observed - predicted) against observed values. The plot includes a horizontal reference line at y=0 and optionally a trend line to identify patterns in residuals.
- Parameters:
- modelbase.BaseEstimator
The trained regression model to evaluate
- Xpd.DataFrame
The input features used for prediction
- ypd.Series
The true target values
- filenamestr
The filename to save the plot to
- add_fit_linebool, optional
Whether to add a trend line to the residual plot, by default False
- Returns:
- None
The plot is saved to the specified filename