plans.stochastic.metrics#
Association and agreement metrics between two samples.
Formulas use \(o_i\) for observed values and \(p_i\) for predicted values.
Functions
|
Compute the Bias (%), positive when predicted overestimates observed. |
|
Get all fit metrics between observed and predicted sample. |
|
Compute the Mean Absolute Error (MAE). |
|
Compute the Pearson correlation coefficient (r), a measure of linear association. |
|
Compute the Root Mean Squared Error (RMSE). |
|
Compute the coefficient of determination (R2), as the fraction of observed variance explained: |
|
Compute the Spearman rank correlation coefficient (rho), a measure of monotonic association. |
- plans.stochastic.metrics.get_metrics(observed, predicted)[source]#
Get all fit metrics between observed and predicted sample.
- Parameters:
observed (
numpy.ndarray) – vector of observed valuespredicted (
numpy.ndarray) – vector of predicted values
- Returns:
dictionary of metrics (r, rho, R2, RMSE, MAE, Bias)
- Return type:
dict
- plans.stochastic.metrics.pearson(x, y)[source]#
Compute the Pearson correlation coefficient (r), a measure of linear association. Symmetric: swapping
xandygives the same value.\[r = \frac{\sum_i (x_i - \bar{x})(y_i - \bar{y})} {\sqrt{\sum_i (x_i - \bar{x})^2} \sqrt{\sum_i (y_i - \bar{y})^2}}\]- Parameters:
x (
numpy.ndarray) – vector of x valuesy (
numpy.ndarray) – vector of y values
- Returns:
r value, from -1 to 1
- Return type:
float
- plans.stochastic.metrics.spearman(x, y)[source]#
Compute the Spearman rank correlation coefficient (rho), a measure of monotonic association. It is the Pearson r of the ranks (ties averaged). Symmetric: swapping
xandygives the same value.\[\rho = r\left( \mathrm{rank}(x), \mathrm{rank}(y) \right)\]- Parameters:
x (
numpy.ndarray) – vector of x valuesy (
numpy.ndarray) – vector of y values
- Returns:
rho value, from -1 to 1
- Return type:
float
- plans.stochastic.metrics.rsq(observed, predicted)[source]#
Compute the coefficient of determination (R2), as the fraction of observed variance explained:
1 - SS_res / SS_tot.Note
Equals r squared only for least-squares linear models with intercept. For other models it can differ, and is negative when the model is worse than the observed mean.
\[R^2 = 1 - \frac{\sum_i (p_i - o_i)^2}{\sum_i (o_i - \bar{o})^2}\]- Parameters:
observed (
numpy.ndarray) – vector of observed valuespredicted (
numpy.ndarray) – vector of predicted values
- Returns:
R2 value
- Return type:
float
- plans.stochastic.metrics.rmse(observed, predicted)[source]#
Compute the Root Mean Squared Error (RMSE).
\[\mathrm{RMSE} = \sqrt{\frac{1}{n} \sum_i (p_i - o_i)^2}\]- Parameters:
observed (
numpy.ndarray) – vector of observed valuespredicted (
numpy.ndarray) – vector of predicted values
- Returns:
RMSE value
- Return type:
float
- plans.stochastic.metrics.mae(observed, predicted)[source]#
Compute the Mean Absolute Error (MAE).
\[\mathrm{MAE} = \frac{1}{n} \sum_i \lvert p_i - o_i \rvert\]- Parameters:
observed (
numpy.ndarray) – vector of observed valuespredicted (
numpy.ndarray) – vector of predicted values
- Returns:
MAE value
- Return type:
float
- plans.stochastic.metrics.bias(observed, predicted)[source]#
Compute the Bias (%), positive when predicted overestimates observed.
\[\mathrm{Bias} = 100 \, \frac{\sum_i (p_i - o_i)}{\sum_i o_i}\]- Parameters:
observed (
numpy.ndarray) – vector of observed valuespredicted (
numpy.ndarray) – vector of predicted values
- Returns:
Bias value
- Return type:
float