get_r
get_r(y_true, y_pred)Calculates the Pearson correlation coefficient (R) and returns the result.
The R value measures the strength and direction of the linear correlation between the true and predicted values.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| y_true | array or list | The actual observed values (ground truth). | required |
| y_pred | array or list | The model predicted values. | required |
Returns
| Name | Type | Description |
|---|---|---|
| float | The calculated R value, ranging from -1.0 to 1.0. |
Examples
>>> # Perfect positive correlation
>>> y_true = [1.0, 2.0, 3.0]
>>> y_pred = [1.0, 2.0, 3.0]
>>> get_r(y_true, y_pred)
1.0>>> # Perfect negative correlation
>>> y_true = [1.0, 2.0, 3.0]
>>> y_pred = [3.0, 2.0, 1.0]
>>> get_r(y_true, y_pred)
-1.0