mstools

mstools.py module.

Contains the functions and routines that are often used but are not included in current common packages. It may include code used in different areas of knowledge.

mstools.mstools.r2_score(y_true, y_pred)[source]

Calculate the coefficient of determination (\(R^2\)).

\(R^2\), pronounced “R squared”, is the proportion of the variance in the dependent variable that is predictable from the independent variable(s).

Parameters
  • y_true (List, tuple or array) – Actual value of the predictied variable.

  • y_pred (List, tuple or array) – Predicted value from the linear regression model.

Returns

Coefficient of determination (\(R^2\)).

Return type

float

Examples

>>> y_true = [1, 2, 3, 4, 5]
>>> y_pred = [1.1, 2.3, 2.8, 4.1, 4.9]
>>> r2_score(y_true, y_pred)
0.984