reservoirpy.observables.rsquare#

reservoirpy.observables.rsquare(y_true, y_pred, dimensionwise=False)[source]#

Coefficient of determination \(R^2\):

\[1 - \frac{\sum^{N-1}_{i=0} (y - \hat{y})^2} {\sum^{N-1}_{i=0} (y - \bar{y})^2}\]

where \(\bar{y}\) is the mean value of ground truth.

Parameters:
  • y_true (array-like of shape (N, features)) – Ground truth values.

  • y_pred (array-like of shape (N, features)) – Predicted values.

  • dimensionwise (boolean, optional) – If True, return a mean squared error for each dimension of the timeseries

Returns:

  • float – Coefficient of determination.

  • If dimensionwise is True, returns a Numpy array of shape $(features, )$.

Examples

>>> from reservoirpy.nodes import Reservoir, Ridge
>>> model = Reservoir(units=100, sr=1) >> Ridge(ridge=1e-8)
>>> from reservoirpy.datasets import mackey_glass, to_forecasting
>>> x_train, x_test, y_train, y_test = to_forecasting(mackey_glass(1000), test_size=0.2)
>>> y_pred = model.fit(x_train, y_train).run(x_test)
>>> from reservoirpy.observables import rsquare
>>> print(rsquare(y_true=y_test, y_pred=y_pred))
0.9999972921653904