{"uid":"cap_eTFF_JEhLHWYZTSbajkAw","slug":"ml-metrics-threshold-sweep-c56fba5d","name":"ML Metrics Threshold Sweep","description":"Sweep every score threshold for binary labels and return the best F1, Youden J and accuracy thresholds with their metrics.","url":"https://ml-metrics.x402tookit.com/threshold-sweep?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["labels","scores"],"properties":{"labels":{"type":"string","description":"True binary labels 0/1, comma-separated or JSON array, up to 10000 values"},"scores":{"type":"string","description":"Model scores (higher = more positive); a sample is predicted positive when score >= threshold"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"sweep":{"type":["array","null"],"items":{"type":"object","properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"recall":{"type":["null","number"]},"youdenJ":{"type":["null","number"]},"accuracy":{"type":["null","number"]},"precision":{"type":["null","number"]},"threshold":{"type":["null","number"]},"specificity":{"type":["null","number"]}}}},"bestF1":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"recall":{"type":["null","number"]},"youdenJ":{"type":["null","number"]},"accuracy":{"type":["null","number"]},"precision":{"type":["null","number"]},"threshold":{"type":["null","number"]},"specificity":{"type":["null","number"]}}},"source":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"negatives":{"type":["null","number"]},"positives":{"type":["null","number"]},"bestYouden":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"recall":{"type":["null","number"]},"youdenJ":{"type":["null","number"]},"accuracy":{"type":["null","number"]},"precision":{"type":["null","number"]},"threshold":{"type":["null","number"]},"specificity":{"type":["null","number"]}}},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"bestAccuracy":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"recall":{"type":["null","number"]},"youdenJ":{"type":["null","number"]},"accuracy":{"type":["null","number"]},"precision":{"type":["null","number"]},"threshold":{"type":["null","number"]},"specificity":{"type":["null","number"]}}},"sweepTruncated":{"type":["boolean","null"]},"youdenTiedThresholds":{"type":["array","null"],"items":{"type":"number"}}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_ZoN07vQBx1XX0bBlQLxaH","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Sweeps every score threshold for binary classification and returns the best F1, Youden J, and accuracy thresholds with full confusion matrix metrics at each point.","exampleAgentPrompt":"Sweep all classification thresholds for my binary model and tell me the best F1, Youden J, and accuracy cutoffs — my true labels are 0,1,0,1,1,0,1,0 and my model scores are 0.1,0.9,0.2,0.8,0.75,0.3,0.85,0.4.","exampleUseCases":[{"title":"Optimizing fraud detection threshold","prompt":"I have a fraud detection model and I need to find the threshold that maximizes F1 score — here are my true fraud labels (0/1) and predicted scores for 500 transactions. Can you sweep all thresholds and tell me which cutoff gives the best F1, what the precision and recall are at that point, and what the best Youden J threshold looks like too?"},{"title":"Medical diagnosis classifier tuning","prompt":"My disease screening model outputs probability scores and I need to pick the operating threshold before deployment. Sweep all thresholds using these true labels and predicted scores, and show me the best Youden J cutoff — that balances sensitivity and specificity which matters most for this use case."},{"title":"Spam filter decision boundary selection","prompt":"I'm building a spam classifier and need to pick the best score cutoff. Here are my ground-truth labels and model scores from a validation set — can you run a full threshold sweep and tell me the thresholds that maximize accuracy and F1, along with the confusion matrix counts at each?"}],"resultDescription":"Returns a full threshold sweep array with TP, FP, TN, FN, precision, recall, specificity, F1, Youden J, and accuracy at every threshold, plus highlighted best-threshold objects for F1, Youden J, and accuracy. Also includes total positive and negative counts, a summary verdict, and degraded-mode flags if computation was partial.","failureModes":["Mismatched array lengths between labels and scores returns an error","Non-binary labels (values other than 0/1) cause invalid input error","Scores outside expected range may produce degenerate thresholds","All-positive or all-negative label sets yield undefined metrics for some thresholds","Input exceeding 10,000 values may be rejected or truncated","Malformed comma-separated or JSON array inputs return parse errors"],"whenToPreferThis":"Choose this endpoint when you need to systematically find the optimal decision threshold for a binary classifier rather than evaluating at a single fixed threshold. It is ideal for model deployment decisions, comparing operating points (F1-optimal vs. specificity-sensitivity balanced via Youden J), or validating that a chosen threshold is truly optimal. Prefer over the confusion-matrix endpoint when you don't yet know which threshold to use, and over manual ROC analysis when you want directly actionable best-threshold recommendations.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:30:42.158Z","isFirstParty":false,"canonicalSlug":"ml-metrics-threshold-sweep-c56fba5d"}