Explained Variance of the Value Head
~12 mincode completion
Implement explained_variance(y_true, y_pred) returning the scalar.
Examples
Perfect predictions explain everything
- Input
- explained_variance([1, 2, 3], [1, 2, 3])
- Output
- 1
Predicting the mean explains nothing
- Input
- explained_variance([1, 2, 3], [2, 2, 2])
- Output
- 0
Predicting backwards is much worse than the mean
- Input
- explained_variance([1, 2, 3], [3, 2, 1])
- Output
- -3
Hints
Hint 1
Convert the input with before doing elementwise work.
Hint 2
Watch for this: used the mean squared error without dividing by the variance of the targets.
Requirements
y_true: (n,) value targetsy_pred: (n,) value predictions
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
EasyEasyEasyEasy
Running Observation Normalisation
Reinforcement Learning: Rewards, Senses and PPO · ~14 min
When Dying Early Pays
Reinforcement Learning: Rewards, Senses and PPO · ~14 min
The TD Error
Reinforcement Learning: Rewards, Senses and PPO · ~14 min
Policy Entropy and the Cost of Exploring
Reinforcement Learning: Rewards, Senses and PPO · ~12 min
Python
import numpy as np
def explained_variance(y_true, y_pred):
"""
Fraction of the target variance the predictions account for.
Args:
y_true: (n,) value targets
y_pred: (n,) value predictions
Returns:
scalar, 1 for perfect, 0 for no better than the mean, negative
for worse. Returns 0.0 when the targets have no variance.
"""
# YOUR CODE HERE
pass