Fix: Add init=0 to prevent empty collection crash during threshold tuning. - #432
Fix: Add init=0 to prevent empty collection crash during threshold tuning.#432vatsalyar wants to merge 4 commits into
Conversation
…ring threshold tuning
…ection Fix: Add init=0 to prevent empty collection crash during threshold tuning
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthrough
ChangesLogistic regression metrics
Estimated code review effort: 1 (Trivial) | ~3 minutes Merge Risk: ⚪ Minimal · up to This localized fix prevents threshold-tuning failures when no positive cases are predicted. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Title checkExplanation The title clearly identifies the fix for empty collections during threshold tuning. It accurately describes the intended behavior, although the implementation uses count over indexed predicates instead of adding init=0 directly. Full details: Linked Issues checkExplanation The changes satisfy issue Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.) ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Refactored the build_metrics function to use count() for better performance and readability.
What this PR does
Fixes #434
Fixes an
ArgumentErrorinmain.jlby adding; init=0to thesum()generators in thebuild_metricsfunction to handle edge cases during threshold tuningKind of change
Checklist
LESSON_TEMPLATE.mdstructure[Name](phases/...)), not bare textdocs/en.mdclaimsPhase / lesson
Phase 2 · 03-logistic-regression
Notes for reviewer
When running
demo_threshold_tuning, extreme thresholds (like0.7) can result in the model predicting exactly zero positive cases. Wheny_predcontains only0s, the generator comprehensions insidebuild_metrics. (e.g.,sum(1 for i in 1:length(y_true) if y_true[i] == 1 && y_pred[i] == 1)) becomes empty. This causes Julia to throw anArgumentError: reducing over an empty collection is not allowed. Adding the; init=0keyword argument resolves this by safely returning 0 and allowing the script to complete successfully.)