Skip to content
DeepForgeby svx
All problems
EasyStatisticsproj-028

Masked RMSE

Problem

Compute RMSE over observed ratings only.

matrix holds the true ratings with 0.0 marking missing entries, and reconstructed holds the predicted matrix. Average the squared differences over nonzero entries and take the square root, returning 0.0 when nothing is observed.

Hint

Masking the zeros is what makes the metric measure generalization, not missing data.

Test cases

case 1
in: [[[5,0],[0,3]],[[5,0],[0,3]]]
expected: 0
case 2
in: [[[5,0],[0,3]],[[4,0],[0,5]]]
expected: 1.5811388300841898
case 3
in: [[[0,0]],[[1,1]]]
expected: 0
case 4
in: [[[1,2],[3,0]],[[1,2],[3,9]]]
expected: 0
Starter codePython
import math
def masked_rmse(matrix, reconstructed):
    # Your code here
    pass

4 test cases · run your code against them in the editor