Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Calculate Classification Accuracy

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Calculate Classification Accuracy. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output