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
Implement Column-Wise Z-Score Standardization
00:00
5 left

Implement Column-Wise Z-Score Standardization

MediumPython

Problem

Smartsheet machine learning pipelines may contain features with very different numeric ranges. Implement a function that transforms a feature matrix using either min-max normalization or population z-score standardization.

Formal Specification

Given X, a non-empty rectangular matrix represented as a list of rows, where each row is one sample and each column is one feature, and a string method:

  1. For method = "minmax", scale each column to the range [0, 1] using (x - minimum) / (maximum - minimum).
  2. For method = "standard", transform each column using (x - mean) / standard_deviation, where the mean and standard deviation are computed across all rows. Use population standard deviation, dividing variance by the number of rows.
  3. If a column has no variation, output 0.0 for every value in that column.
  4. Return a new matrix. Do not modify X.

Constraints

  • 1 <= len(X) <= 10^4
  • 1 <= len(X[0]) <= 100
  • X is rectangular
  • Every feature value is a finite number
  • method is either "minmax" or "standard"

Function Signature

def scale_features(X, method):
Interviewer

Your question is Implement Column-Wise Z-Score Standardization. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.