You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNestProblem Set
🔥Binary Cross-Entropy Loss (ML Classifier)Medium
MediumAI & Machine Learning•Acceptance: 58.4%
Binary Cross-Entropy Loss (ML Classifier)
Real-World Engineering Context
Standard loss objective function for logistic regression, binary classification, and transformer reward models in RLHF (Reinforcement Learning from Human Feedback).
Given true labels `yTrue` (0 or 1) and predicted probabilities `yPred` (between 0 and 1 exclusive), compute the mean Binary Cross-Entropy (BCE) loss across all samples: `-1/N * sum(y * log(p) + (1 - y) * log(1 - p))` rounded to 4 decimal places.
Sample Test Cases
Input: [[1,0],[0.9,0.1]]
Expected: 0.1054
Input: [[1,0],[0.5,0.5]]
Expected: 0.6931
Constraints
- yTrue.length == yPred.length
- 1 <= yTrue.length <= 10^4
- 0.0001 <= yPred[i] <= 0.9999
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.