🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #54

Missing Values

Missing values are gaps in your data — and why a value is missing matters as much as how many are missing, because it determines whether it's safe to fill the gap or whether doing so introduces bias.

Detecting Missing Values

import pandas as pd

df = pd.read_csv("survey.csv")

print(df.isnull().sum())              # missing count per column
print(df.isnull().mean() * 100)        # missing percentage per column
print(df[df["income"].isnull()])       # inspect the actual rows with gaps

Three Types of "Missing" — Why It Matters

TypeMeaningExampleSafe to Impute?
MCAR (Missing Completely At Random)Missingness is unrelated to any variableA sensor randomly drops readingsYes — imputation introduces little bias
MAR (Missing At Random)Missingness depends on other observed variablesOlder survey respondents skip the "salary" question more oftenYes, if you use those related variables to impute
MNAR (Missing Not At Random)Missingness depends on the missing value itselfHigh earners specifically decline to state salaryRisky — naive imputation systematically biases the result

Practical Use Cases

  • Deciding whether to drop a column entirely (if >50–60% missing, often not worth keeping) vs. imputing
  • Flagging missingness itself as a feature — sometimes "did the customer skip this field?" is predictive on its own

Common Mistakes

  • Filling every missing value the same way regardless of missingness type — especially dangerous for MNAR data.
  • Dropping rows with missing values without checking how many rows that removes — silently losing 30% of your dataset is rarely the right call.
  • Imputing the target variable — rows with a missing target should be dropped, never filled in.

Interview Relevance

Q: "Why does it matter whether data is MCAR, MAR or MNAR before you impute it?" Because naive imputation (like filling with the mean) assumes the missingness carries no information — true for MCAR, often false for MNAR, where the fact that a value is missing is itself informative and imputing it flattens a real signal.

Practice Question

A loan application dataset has a "monthly_income" column that's missing more often for applicants who were ultimately rejected. Is this more likely MCAR, MAR, or MNAR — and why does it matter for how you handle it?

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Missing Values – FAQs

Quick answers about learning Missing Values in Machine Learning.

This free note from CodingNow 2.0 explains Missing Values in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Missing Values, is 100% free with no signup required.
With focused practice, most students grasp Missing Values in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now