slickml.metrics._regression
#
Module Contents#
Classes#
Regression Metrics is a wrapper to calculate all the regression metrics in one place. |
- class slickml.metrics._regression.RegressionMetrics[source]#
Regression Metrics is a wrapper to calculate all the regression metrics in one place.
Notes
In case of multioutput regression, calculation methods can be chosen among
"raw_values"
,"uniform_average"
, and"variance_weighted"
.- Parameters:
y_true (Union[List[float], np.ndarray, pd.Series]) – Ground truth target (response) values
y_pred (Union[List[float], np.ndarray, pd.Series]) – Predicted target (response) values
multioutput (str, optional) – Method to calculate the metric for
multioutput targets
where possible values are"raw_values"
,"uniform_average"
, and"variance_weighted"
."raw_values"
returns a full set of scores in case of multioutput input."uniform_average"
scores of all outputs are averaged with uniform weight."variance_weighted"
scores of all outputs are averaged, weighted by the variances of each individual output, by default “uniform_average”precision_digits (int, optional) – The number of precision digits to format the scores dataframe, by default 3
display_df (bool, optional) – Whether to display the formatted scores’ dataframe, by default True
- plot(figsize=(12, 16), save_path=None, display_plot=False, return_fig=False)[source]#
Plots regression metrics
- y_residual_#
Residual values (errors) calculated as
(y_true - y_pred)
- Type:
np.ndarray
- y_residual_normsq_#
Square root of absolute value of
y_residual_
- Type:
np.ndarray
- r2_#
\(R^2\) score (coefficient of determination) with a possible value between 0.0 and 1.0
- Type:
- deviation_#
Arranged deviations to plot REC curve
- Type:
np.ndarray
- accuracy_#
Calculated accuracy at each deviation to plot REC curve
- Type:
np.ndarray
- y_ratio_#
Ratio of
y_pred/y_true
- Type:
np.ndarray
- metrics_dict_#
Rounded metrics based on the number of precision digits
- metrics_df_#
Pandas DataFrame of all calculated metrics
- Type:
pd.DataFrame
References
[Tahmassebi-et-al]Tahmassebi, A., Gandomi, A. H., & Meyer-Baese, A. (2018, July). A Pareto front based evolutionary model for airfoil self-noise prediction. In 2018 IEEE Congress on Evolutionary Computation (CEC) (pp. 1-8). IEEE. https://www.amirhessam.com/assets/pdf/projects/cec-airfoil2018.pdf
[rec-curve]Bi, J., & Bennett, K. P. (2003). Regression error characteristic curves. In Proceedings of the 20th international conference on machine learning (ICML-03) (pp. 43-50). https://www.aaai.org/Papers/ICML/2003/ICML03-009.pdf
Examples
>>> from slickml.metrics import RegressionMetrics >>> rm = RegressionMetrics( ... y_true=[3, -0.5, 2, 7], ... y_pred=[2.5, 0.0, 2, 8] ... ) >>> m = rm.get_metrics() >>> rm.plot()
- display_df :Optional[bool] = True#
- multioutput :Optional[str] = uniform_average#
- precision_digits :Optional[int] = 3#
- y_pred :Union[List[float], numpy.ndarray, pandas.Series]#
- y_true :Union[List[float], numpy.ndarray, pandas.Series]#
- get_metrics(dtype: Optional[str] = 'dataframe') Union[pandas.DataFrame, Dict[str, Optional[float]]] [source]#
Returns calculated metrics with desired dtypes.
Currently, available output types are
"dataframe"
and"dict"
.- Parameters:
dtype (str, optional) – Results dtype, by default “dataframe”
- Returns:
Union[pd.DataFrame, Dict[str, Optional[float]]]
- plot(figsize: Optional[Tuple[float, float]] = (12, 16), save_path: Optional[str] = None, display_plot: Optional[bool] = False, return_fig: Optional[bool] = False) Optional[matplotlib.figure.Figure] [source]#
Plots regression metrics.
- Parameters:
figsize (Tuple[float, float], optional) – Figure size, by default (12, 16)
save_path (str, optional) – The full or relative path to save the plot including the image format such as “myplot.png” or “../../myplot.pdf”, by default None
display_plot (bool, optional) – Whether to show the plot, by default False
return_fig (bool, optional) – Whether to return figure object, by default False
- Returns:
Figure, optional