Skip to content
QuantReadySign In
#467easyMachine Learning

K-Fold Cross-Validation

Problem

You are evaluating a model using KK-fold cross-validation on NN data points. Each fold produces a test error eke_k.

Compute:

  1. The mean CV error: CV=1Kk=1Kek\text{CV} = \frac{1}{K}\sum_{k=1}^{K} e_k

  2. The standard error: SE=s2K\text{SE} = \sqrt{\frac{s^2}{K}} where s2=1K1k=1K(ekCV)2s^2 = \frac{1}{K-1}\sum_{k=1}^{K}(e_k - \text{CV})^2

Input Format

  • Line 1: Two space-separated integers N K
  • Line 2: KK space-separated floats (the fold errors)

Output Format

Two space-separated values: mean_error standard_error, each to 4 decimal places.

Examples

Example 1
Input(Line 1: Two space-separated integers N K)
100 5
0.12 0.15 0.11 0.14 0.13
Output
0.1300 0.0071

Mean = 0.13. Sample var = 0.00025. SE = sqrt(0.00025/5) = 0.0071.

Example 2
Input(Line 1: Two space-separated integers N K)
90 10
0.20 0.18 0.22 0.19 0.21 0.17 0.20 0.23 0.18 0.22
Output
0.2000 0.0063

Mean = 0.20. Sample var = 0.000400/9 = 0.0000444. SE = sqrt(0.0000444/10) = 0.0021. Wait: s^2 = sum of (ei-0.2)^2 / 9. Let me recompute. Deviations: 0,-.02,.02,-.01,.01,-.03,0,.03,-.02,.02. Sum sq = .0004+.0004+.0001+.0001+.0009+0+.0009+.0004+.0004 = 0.0036. s^2 = 0.0036/9 = 0.0004. SE = sqrt(0.0004/10) = 0.0063.

Constraints

  • 2 ≤ K ≤ N
  • 2 ≤ N ≤ 100000
  • 0 ≤ each error ≤ 1
  • Output mean error and standard error to 4 decimal places

Execution limits: 2s · 256MB

Loading interactive editor…