BLOGLLM Logo
Go Pro
Guest
Not signed in
All BlogsCoursesPracticeInterview prepSeriesTagsBookmarksPricing
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboardGames
Articles
Practice / Real-world constraints10 of 10 in topic

895. How many eval examples can you afford?

EasyReal-world constraints

Why it matters Teams often report eval numbers that differ by less than their own noise. Sizing the eval set before paying for labels avoids that.

You want an accuracy estimate with a 95 percent confidence interval of half-width at most margin, using the normal approximation.

Write eval_budget(expected_acc, margin, cost_per_example, budget_usd, z=1.96).
- needed examples: n = ceil(z ** 2 * p * (1 - p) / margin ** 2), with p = expected_acc
- cost = n * cost_per_example
- affordable: cost <= budget_usd
- if not affordable, you can label only m = floor(budget_usd / cost_per_example) examples, and the margin you get is z * sqrt(p * (1 - p) / m) (use None if m is 0). If affordable, achieved_margin is the margin from n examples.

Inputs: expected_acc in (0, 1), margin > 0, cost_per_example > 0, budget_usd >= 0.

Return a dict {"needed": int, "cost": rounded to 2 decimals, "affordable": bool, "achieved_margin": rounded to 4 decimals or None}.

Functiondef eval_budget(expected_acc, margin, cost_per_example, budget_usd, z=1.96)

Example 1

Input: eval_budget(0.8, 0.02, 0.5, 1000)

Output: {'needed': 1537, 'cost': 768.5, 'affordable': True, 'achieved_margin': 0.02}

Example 2

Input: expected_acc = 0.8, margin = 0.02, cost_per_example = 0.5, budget_usd = 500

Output: {'needed': 1537, 'cost': 768.5, 'affordable': False, 'achieved_margin': 0.0248}

Example 3

Input: expected_acc = 0.5, margin = 0.05, cost_per_example = 2.0, budget_usd = 0

Output: {'needed': 385, 'cost': 770.0, 'affordable': False, 'achieved_margin': None}

Constraints

  • Python 3 standard library. Code runs in your browser.
  • Your code must pass all 5 tests to be accepted.
Hint 1

n = ceil(z^2 p (1 - p) / margin^2).

Hint 2

If the cost is over budget, compute how many you can buy and the margin they give.

Hint 3

Return None for the margin when you can buy zero examples.

Common mistakes
  • Using p = 0.5 instead of the expected accuracy.
  • Forgetting the ceiling.
  • Squaring z twice.
Understand the idea

The standard error of an accuracy estimate is sqrt(p (1 - p) / n), and a 95 percent interval is about 1.96 standard errors each side. Halving the margin needs four times the examples. For p = 0.8 and a margin of 2 points you need 1537 examples; at $0.50 each that is $768.50.

Shapes and data flow
Scalars in, dict out.
Topics
Real-world constraints
Similar questions
  • How many tokens can my budget train?Easy
  • Self-host or pay per token?Easy
  • Cheapest GPU fleet that meets throughput and memoryMedium
  • Largest decode batch under a latency SLOMedium
All Real-world constraints problems
Report
895 / 903
Python 3solution.pyPython idle
1
2
3
4
5
import math
def eval_budget(expected_acc, margin, cost_per_example, budget_usd, z=1.96):
# your code here
pass
​

Run checks these cases in your browser, no sign-in needed. Submit checks all 5 tests.

Ctrl/Cmd + Enter to run
© BlogLLM, Bengaluru, IndiaAboutTermsPrivacyRefundsDMCAContactRSS