Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Calculate Classification Accuracy
00:00
5 left

Calculate Classification Accuracy

EasyPython

Problem

Given two arrays of equal length, y_true and y_pred, return the classification accuracy as a floating-point value. Accuracy is defined as the number of matching labels divided by the total number of labels. If the input arrays have different lengths or are empty, return 0.0.

Constraints

  • 0 <= len(y_true), len(y_pred) <= 10^5
  • Labels may be integers or strings
  • Return 0.0 if the arrays are empty or have different lengths

Function Signature

def calculate_accuracy(y_true, y_pred):
Interviewer

Your question is Calculate Classification Accuracy. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.