Sign In
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 RoleNest
🔥Binary Cross-Entropy Loss (ML Classifier)Medium
DAILY PROBLEM OF THE DAY+50 XP • Daily Streak

Solve today's challenge or tackle one of the 3 Super Hard challenges for +150 XP.

MediumAI & Machine Learning•Acceptance: 58.4%

Binary Cross-Entropy Loss (ML Classifier)

Targeted in FAANG & Tech OA:GoogleAmazonMicrosoftSwiggyUber
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
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.