Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-052

Anomaly Z-Score on Residuals

Problem

Score a new value against a list of residuals. Compute the mean and population standard deviation of residuals, then return (value - mean) / std.

Return 0.0 if residuals is empty or has zero variance.

Hint

A z-score beyond 2 flags a potentially unusual observation.

Test cases

case 1
in: [[1,2,3,4],5]
expected: 2.23606797749979
case 2
in: [[0,0,0],1]
expected: 0
case 3
in: [[10,10,10,10],10]
expected: 0
case 4
in: [[2,4,6],8]
expected: 2.449489742783178
Starter codePython
def anomaly_zscore(residuals, value):
    # Your code here
    pass

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