Data Collection & Pre-processing MCQs for the NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Data collection and pre-processing is the work of gathering raw data and turning it into a clean, numeric, consistently scaled table that a model can learn from: handling missing values, scaling features, encoding categories and dealing with outliers. It is the fourth of the 17 topics in the AI / Machine Learning and Data Analytics area, which carries 10% of the NSCT according to HEC's Areas of Competencies.

Expect quick calculations (a min-max value, a z-score, an imputed mean) and scenario questions about data leakage. Pandas syntax from Python for AI & Data Analytics shows up here too.

Data collection and splitting

Primary data is collected by you for your purpose, such as your FYP survey; secondary data was collected by someone else, such as a public dataset. Han and Kamber group the later work into cleaning, integration (merging sources), reduction and transformation.

Before any fitting, split the data. A stratified split keeps class proportions equal in both sets: with 2,000 rows, 5% positive and a 20% test set, the test set gets 400 rows including 20 positives. Time-ordered data needs a chronological split instead of a random one.

Exam angle: every statistic used for pre-processing (mean, min, max, category list) must be learnt from the training set only. Fitting on all the data is data leakage.

Missing values

Rubin's three mechanisms decide what is safe:

Mechanism Missingness depends on Example
MCAR (completely at random) Nothing Sensor packets lost at random
MAR (at random) Other observed columns Older respondents skip an online question
MNAR (not at random) The missing value itself High earners hide their income

Options are deletion (rows or columns), simple imputation (mean, median, mode), model-based imputation (KNN or regression) and adding a "was missing" indicator column. For [5, NaN, 9, 10], mean imputation fills 8 and median imputation fills 9.

Exam angle: mean imputation keeps the mean but shrinks the variance, because every filled value has zero deviation.

Scaling

Method Formula Result Outlier-sensitive?
Min-max normalisation (x - min) / (max - min) 0 to 1 on training data Yes
Standardisation (z-score) (x - mean) / sd Mean 0, sd 1 Somewhat
Robust scaling (x - median) / IQR Centred on median No
Decimal scaling x / 10^j All |x| below 1 Yes

Example: with training min 0 and max 200, the value 50 becomes 0.25. A test value of 250 becomes 1.25, because the scaler does not clip.

Exam angle: distance-based and gradient-based models (KNN, SVM, k-means, neural networks) need scaling; decision trees and random forests do not.

Encoding

Exam angle: label-encoding a nominal column for a linear model invents an order, so the model treats blue = 2 as "twice" green = 1.

Outliers

Two standard detection rules:

After detection you can remove, cap (winsorise), transform (log) or keep the value. An outlier is not automatically an error: in fraud detection the extreme rows are often the very cases you want.

Common traps

Worked examples

1. Understanding. A hospital dataset has blank 'pain score' entries for patients who were unconscious on arrival, and a separate, complete column records consciousness. Which mechanism is this? Answer: MAR. Whether the value is missing depends on another observed column (consciousness), not on the pain score itself. Imputation that uses that column, such as model-based imputation, handles it better than plain deletion.

2. Application. A feature has mean 120 and standard deviation 15. What is the z-score of 90? Answer: (90 - 120) / 15 = -2, two standard deviations below the mean.

3. Analysis. A team one-hot encodes 'city' on the full dataset, finds a city that appears only in the test rows, then splits. Is anything wrong? Answer: yes. The encoder learnt its category list from test data, a mild form of leakage. Fit the encoder on training data and set it to ignore unknown categories at prediction time, so a new city maps to all zeros.

Practise

The quiz below has 100 questions on this topic, filterable by tier and difficulty.

Practise: 100 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. Values in a sensor log are missing because a few readings were lost at random during network glitches, unrelated to any variable. Which missing-data mechanism is this?

    1. Missing At Random (MAR)
    2. Missing Completely At Random (MCAR)
    3. Missing Not At Random (MNAR)
    4. Structurally missing
    Show answer

    Answer: B. Missing Completely At Random (MCAR)

    Under MCAR the chance that a value is missing does not depend on any observed or unobserved data, as with readings dropped by random glitches. Dropping such rows loses data but does not bias estimates.

  2. A 'city' column holds Lahore, Karachi and Quetta, with no natural order. Which encoding is usually the safest choice for a linear model?

    1. Ordinal (label) encoding 0, 1, 2
    2. Min-max scaling
    3. One-hot encoding
    4. Binning
    Show answer

    Answer: C. One-hot encoding

    For nominal categories one-hot encoding creates one binary column per city, so the model does not read a false order such as Quetta > Karachi > Lahore. Ordinal codes imply an order that does not exist.

  3. With default settings, into which range does min-max normalisation map the training values of a feature?

    1. -1 to 1
    2. Mean 0 and standard deviation 1
    3. 0 to 1
    4. 1 to 10
    Show answer

    Answer: C. 0 to 1

    Min-max normalisation computes (x - min) / (max - min), so the training minimum maps to 0 and the maximum to 1. A custom range such as -1 to 1 is possible, but 0 to 1 is the default.

  4. After z-score standardisation, what are the mean and standard deviation of the transformed training feature?

    1. Mean 0, standard deviation 1
    2. Mean 1, standard deviation 0
    3. Minimum 0, maximum 1
    4. Mean 0.5, standard deviation 0.5
    Show answer

    Answer: A. Mean 0, standard deviation 1

    Standardisation computes z = (x - mean) / standard deviation, which centres the feature at mean 0 and rescales it to standard deviation 1. It does not bound values to a fixed range.

  5. What is the correct way to apply a standard scaler when you have a train/test split?

    1. Fit it on the whole dataset before splitting
    2. Fit one scaler on the training set and a separate one on the test set
    3. Fit it on the test set only, since that is what is evaluated
    4. Fit it on the training set only, then transform both sets with those parameters
    Show answer

    Answer: D. Fit it on the training set only, then transform both sets with those parameters

    The mean and standard deviation must come from training data alone and then be reused on the test set. Fitting on all data, or on the test set, lets test information leak into training and inflates the measured score.

  6. For which feature is ordinal encoding (0, 1, 2, ...) most appropriate?

    1. Education level: Matric, Intermediate, Bachelor's, Master's
    2. Blood group: A, B, AB, O
    3. Province: Punjab, Sindh, KP, Balochistan
    4. Mobile network: Jazz, Zong, Ufone, Telenor
    Show answer

    Answer: A. Education level: Matric, Intermediate, Bachelor's, Master's

    Ordinal encoding suits categories with a natural order. Education levels rise from Matric to Master's, so integer codes preserve real information. The other three are nominal and are better one-hot encoded.

  7. Which algorithm's predictions are essentially unaffected by feature scaling?

    1. k-nearest neighbours
    2. Decision tree
    3. SVM with an RBF kernel
    4. k-means clustering
    Show answer

    Answer: B. Decision tree

    A decision tree splits on thresholds of one feature at a time, and a monotonic rescaling just moves the threshold, so the tree is the same. KNN, RBF-SVM and k-means all rely on distances, which scaling changes.

  8. When is median imputation usually preferred over mean imputation for a numeric column?

    1. When the column is categorical
    2. When the column is skewed or has outliers
    3. When the column has no missing values
    4. When the column is perfectly normally distributed
    Show answer

    Answer: B. When the column is skewed or has outliers

    The median is robust: a few extreme values barely move it, while they can drag the mean far from typical values. For skewed data such as income, the median gives a more representative fill value.

  9. Your FYP team designs a questionnaire and collects responses from 300 students yourselves. What kind of data is this?

    1. Primary data
    2. Secondary data
    3. Synthetic data
    4. Metadata
    Show answer

    Answer: A. Primary data

    Primary data is collected first-hand by the researcher for the current purpose, as with your own questionnaire. Secondary data was collected by someone else, such as a published Kaggle or census dataset.

  10. Which statistics does a robust scaler use, making it less sensitive to outliers than standardisation?

    1. The mean and the standard deviation
    2. The minimum and the maximum
    3. The mode and the range
    4. The median and the interquartile range (IQR)
    Show answer

    Answer: D. The median and the interquartile range (IQR)

    A robust scaler computes (x - median) / IQR. Both the median and the IQR ignore the extreme tails, so a handful of outliers do not squash the rest of the data as they do with min-max or z-score scaling.

FAQs

Should I normalise or standardise my data?

Use min-max normalisation when a model expects a bounded range, such as pixel values for a neural network, and there are few outliers. Use standardisation for most linear models, SVMs and PCA, especially when features look roughly bell-shaped. With strong outliers, a robust scaler based on the median and IQR is safer than either.

Is it better to drop or impute missing values?

Drop rows only when very few are missing and the data is plausibly MCAR. Drop a column when most of it is missing and it adds little. Otherwise impute: median for skewed numbers, mode for categories, or KNN and model-based imputation when columns are related. Adding a missing-indicator column keeps any signal in the missingness itself.

What is data leakage in pre-processing?

Leakage happens when information that would not be available at prediction time reaches the model during training. Common causes are fitting scalers, imputers or encoders on the whole dataset, resampling before the split, and features recorded after the outcome, such as a debt collection date when predicting default. Leakage makes test scores look better than real performance.

Next step

Continue with Exploratory Data Analysis (EDA), the next topic in HEC's order. You can also return to the AI & ML MCQs hub or test yourself in an NSCT mock test.