1. LPU MCA Semester 1
  2. CAB107
  3. Unit 3

CAB107 · Unit 3: Data collection, preprocessing and visualization

Feature engineering, data transformation and normalization

10 practice questions · in the MTE and ETE syllabus

Key points

  • Min-max maps to 0-1; standardisation gives mean 0 and std 1
  • Scaling matters for k-NN, K-Means and gradient descent
  • Fit scalers on training data only to avoid leakage
  • Scaling does not remove outliers

Feature engineering creates or transforms input variables so a model can learn better, for example extracting the month from a date or encoding categories as numbers. Categorical variables are encoded with one-hot encoding for nominal categories or ordinal encoding when an order exists.

Scaling puts numeric features on comparable ranges:

MethodFormulaResult
Min-max(x - min) / (max - min)Values in 0 to 1
Standardisation (z-score)(x - mean) / stdMean 0, standard deviation 1

Worked example: for values 10, 20, 30, 40, 50 min-max scaling maps 20 to (20 - 10) / 40 = 0.25.

Scaling matters for distance-based methods such as k-NN and K-Means and for gradient descent, because features with large ranges would dominate distances and slow the updates. Tree-based models are mostly insensitive to scaling. Scaling does not remove outliers and does not guarantee higher accuracy.

from sklearn.preprocessing import StandardScaler
sc = StandardScaler().fit(X_train)
X_train_s = sc.transform(X_train)
X_test_s = sc.transform(X_test)

Exam trap: fit the scaler on the training set only. Fitting it on the full dataset before splitting leaks test information into preprocessing and makes evaluation look better than it should.

Try two questions

Question 1 · Tier 3, Apply

A feature has mean 50 and standard deviation 8. What is the standardised value of 62?

  1. 12.0
  2. 0.67
  3. 1.0
  4. 1.5
Show the answer

D. Standardise with z = (x - mean) / sd = (62 - 50) / 8 = 1.5.

Why not A: 12.0 is only the difference from the mean.

Why not B: 0.67 inverts the ratio, giving 8 / 12.

Why not C: 1.0 would correspond to the value 58.

Question 2 · Tier 3, Apply

A feature has minimum 20 and maximum 70. What is the min-max scaled value of 35?

  1. 0.5
  2. 0.7
  3. 0.3
  4. 15
Show the answer

C. (35 - 20) / (70 - 20) = 15 / 50 = 0.3.

Why not A: 0.5 would be the midpoint, which is 45, not 35.

Why not B: 0.7 would correspond to 55.

Why not D: 15 is the distance from the minimum, not yet divided by the range.