FAILURE MAP
← Case archive

FA-6256 / Statistics / Open access

Coefficient of determination rational · case 01

Residual fraction is returned instead of explained fraction.

Verified by executionVariant 1 · 4 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Residual fraction is returned instead of explained fraction.

VERIFIED REPAIR

Apply the specified mathematical contract directly, preserving all terms and boundary cases: return str(1-Fraction(sum((a-p)**2 for a,p in zip(actual,predicted)),sum((Fraction(a)-Fraction(sum(actual),len(actual)))**2 for a in actual)))

Unsuccessful approach: Clamping discards valid negative scores for predictions worse than the mean.

Case contract

Integer finite observations and equal lengths for paired samples. Counts and weights are nonnegative. Rational results use reduced Fraction strings. Empty or undefined statistics return None where shown. Nonempty actual observations have positive variance; R squared may be negative and is not clamped. Exact operational definition: str(1-Fraction(sum((a-p)**2 for a,p in zip(actual,predicted)),sum((Fraction(a)-Fraction(sum(actual),len(actual)))**2 for a in actual)))

Why this case matters

Small exact fixtures expose this error without platform timing, external services, or probabilistic observations. Statistical estimators results depend on the stated convention.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(actual, predicted):
    return str(Fraction(sum((a-p)**2 for a,p in zip(actual,predicted)),sum((Fraction(a)-Fraction(sum(actual),len(actual)))**2 for a in actual)))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 2, 3], [1, 2, 3])', solve(*([1, 2, 3], [1, 2, 3])), '1')
check('fixture 2: ([1, 2, 3], [2, 2, 2])', solve(*([1, 2, 3], [2, 2, 2])), '0')
check('fixture 3: ([1, 2, 3], [4, 4, 4])', solve(*([1, 2, 3], [4, 4, 4])), '-6')
check('fixture 4: ([0, 2], [0, 0])', solve(*([0, 2], [0, 0])), '-1')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1: ([1, 2, 3], [1, 2, 3])01Failed
fixture 2: ([1, 2, 3], [2, 2, 2])10Failed
fixture 3: ([1, 2, 3], [4, 4, 4])7-6Failed
fixture 4: ([0, 2], [0, 0])2-1Failed

SHA-256 / 0c28089ce4193d256b3501839736a79222826f458b0b39f066bda9a4aff06522

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(actual, predicted):
    return str(max(0,1-Fraction(sum((a-p)**2 for a,p in zip(actual,predicted)),sum((Fraction(a)-Fraction(sum(actual),len(actual)))**2 for a in actual))))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 2, 3], [1, 2, 3])', solve(*([1, 2, 3], [1, 2, 3])), '1')
check('fixture 2: ([1, 2, 3], [2, 2, 2])', solve(*([1, 2, 3], [2, 2, 2])), '0')
check('fixture 3: ([1, 2, 3], [4, 4, 4])', solve(*([1, 2, 3], [4, 4, 4])), '-6')
check('fixture 4: ([0, 2], [0, 0])', solve(*([0, 2], [0, 0])), '-1')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1: ([1, 2, 3], [1, 2, 3])11Passed
fixture 2: ([1, 2, 3], [2, 2, 2])00Passed
fixture 3: ([1, 2, 3], [4, 4, 4])0-6Failed
fixture 4: ([0, 2], [0, 0])0-1Failed

SHA-256 / 4c1d05e064f071075f67fa0d64e58e36bb032e44ba37ad11c4f56cc3c85a6091

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR

N = 1
observations = []
def solve(actual, predicted):
    return str(1-Fraction(sum((a-p)**2 for a,p in zip(actual,predicted)),sum((Fraction(a)-Fraction(sum(actual),len(actual)))**2 for a in actual)))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: ([1, 2, 3], [1, 2, 3])', solve(*([1, 2, 3], [1, 2, 3])), '1')
check('fixture 2: ([1, 2, 3], [2, 2, 2])', solve(*([1, 2, 3], [2, 2, 2])), '0')
check('fixture 3: ([1, 2, 3], [4, 4, 4])', solve(*([1, 2, 3], [4, 4, 4])), '-6')
check('fixture 4: ([0, 2], [0, 0])', solve(*([0, 2], [0, 0])), '-1')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
fixture 1: ([1, 2, 3], [1, 2, 3])11Passed
fixture 2: ([1, 2, 3], [2, 2, 2])00Passed
fixture 3: ([1, 2, 3], [4, 4, 4])-6-6Passed
fixture 4: ([0, 2], [0, 0])-1-1Passed

SHA-256 / 350c712a5bc9eaa13407abfe959d4f2eb0710c4c48dc73a6a7613999badfa864

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:59.530423+00:00.

Case digest / 63d5101f7d7c545913ee7080c73cd81cb37d281669a82bd120f6e603ee9a3683