Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Balancing Imbalanced Multi-Label Data
00:00
5 left

Balancing Imbalanced Multi-Label Data

HardSQL · PostgreSQL

Problem

Given an imbalanced multi-label dataset of image tags, write a data pipeline to reweight or sample instances for balanced mini-batch training.

Use PostgreSQL and return a deterministic mini-batch of six tagged images. Compute each image's sampling weight from the frequency of its associated tags, excluding images without a valid tag.

Output

  1. One row per selected image, with image_id, image_name, sampling_weight, and batch_rank
  2. Include six images with the highest weights, breaking ties by image_id ascending
  3. Order by batch_rank ascending

Schema

images
ColumnTypeDescription
image_idPKINTUnique image identifier
image_nameVARCHAR(100)Image file name
image_tags
ColumnTypeDescription
image_tag_idPKINTUnique image-tag relationship identifier
image_idINTReferenced image identifier
tag_idINTImage tag identifier; null indicates an invalid or missing tag
Tablesimagesimage_tags
Interviewer

Your question is Balancing Imbalanced Multi-Label Data. Start with the requirements and the two tables 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.