∑GateAndNet
PlannerSign Up
INTERMEDIATEFrequently Tested 4 min read 2 views

Data Science Pipelines: EDA, Feature Scaling, OLAP Schemas & SQL Window Functions

Preventing train-test data leakage, Z-score vs Min-Max vs Robust IQR scaling, MCAR/MAR/MNAR missingness, Star vs Snowflake OLAP cube operations, and SQL ROW_NUMBER / RANK / DENSE_RANK.

1. Feature Engineering & The Cardinal Sin of Data Leakage

Common Exam Mistake

Train-Test Preprocessing Leakage: Always compute μ,σ\mu, \sigma, imputation medians, target encodings, and PCA eigenvectors on the Training Split ONLY (or inside each fold of KK-Fold Cross-Validation), then apply scaler.transform(X_test)! Fitting a scaler or oversampler (SMOTE) on the full dataset before splitting leaks test distribution statistics and inflates validation metrics!

Missing Data MechanismDefinitionSafe Handling Strategy
MCAR (Missing Completely at Random)Missingness independent of both observed & unobserved valuesListwise deletion is unbiased (loses power); median/mean imputation
MAR (Missing at Random)Missingness depends only on observed covariates (e.g. age/role)Multiple Imputation (MICE), k-NN / iterative model imputation
MNAR (Missing Not at Random)Missingness depends on the missing value itself (e.g. high earners hiding income)Add explicit is_missing indicator flag + domain modeling

2. Data Warehousing: Star vs Snowflake Schema & OLAP Operations

  • Star Schema: Central denormalized numeric Fact Table surrounded by 1-hop Dimension Tables (in 2NF/denormalized)   ⟹  \implies fewer JOINs, faster analytical OLAP queries!
  • Snowflake Schema: Normalizes dimension hierarchies into 3NF sub-tables   ⟹  \implies saves storage & avoids update anomalies, but slower multi-join reads.
  • OLAP Cube Operations: Roll-Up (aggregate up hierarchy: City →\to Country), Drill-Down (finer granularity: Year →\to Quarter), Slice (fix 11 dimension, e.g. Year = 2026), Dice (sub-cube range across ≥2\ge 2 dimensions), Pivot (rotate axes).

3. SQL Analytical Window Functions (ROW_NUMBER vs RANK vs DENSE_RANK)

Suppose salaries in a department are [90, 80, 80, 70] ordered DESC:

sql
SELECT emp_name, salary,
       ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rn,
       RANK()       OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rnk,
       DENSE_RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS drnk
FROM employees;
  • ROW_NUMBER(): 1, 2, 3, 4 (unique sequential integers, breaks ties arbitrarily)
  • RANK(): 1, 2, 2, 4 (ties share rank, skips 3)
  • DENSE_RANK(): 1, 2, 2, 3 (ties share rank, never skips — always use DENSE_RANK() = N for "Nth highest distinct salary"!)
Key Formulas Summary
Feature Scaling Transformations & Tukey IQR Outlier Fences
z=x−μσ,xrobust=x−MedianIQR,Outlier if x∉[Q1−1.5 IQR,  Q3+1.5 IQR]z = \frac{x - \mu}{\sigma}, \qquad x_{\text{robust}} = \frac{x - \text{Median}}{\text{IQR}}, \qquad \text{Outlier if } x \notin [Q_1 - 1.5\,\text{IQR},\; Q_3 + 1.5\,\text{IQR}]
Note: IQR = Q_3 - Q_1 (75th minus 25th percentile) is resistant to extreme outliers unlike mean/std!
#Data Science#Feature Engineering#Data Leakage#OLAP#Star Schema#SQL Window Functions

Practice Questions on This Chapter (3)

Q1GATE DA Data ScienceMCQMEDIUM
+2M • -0.67

A dataset feature has quartiles Q1=20Q_1 = 20, Median=32\text{Median} = 32, and Q3=50Q_3 = 50. Under Tukey’s 1.5×IQR1.5 \times \text{IQR} rule, any observation strictly above which upper fence is flagged as an outlier?

⚡ Click an option above to verify instantly
Q2GATE DA SQL & WarehousingMCQEASY
+2M • -0.67

For the ordered score column [100, 95, 95, 90], what sequence of integers is returned by SQL RANK() OVER (ORDER BY score DESC) vs DENSE_RANK() OVER (ORDER BY score DESC)?

⚡ Click an option above to verify instantly
Q3GATE DA Data LeakageMCQEASY
+1M • -0.33

Which step in a Data Science pipeline introduces train-test data leakage and produces overly optimistic validation scores?

⚡ Click an option above to verify instantly
Previous TopicStatistical Inference: MLE, MAP Estimation, Confidence Intervals & Hypothesis TestingNext Topic A/B Testing Power Analysis, Simpson’s Paradox & Correlation vs Causality Traps