Sample questions
Fe Categorical Encoding MechanicsDifficulty 1
A single categorical column holds exactly three distinct values. A one-hot encoder is fitted on it with default settings (scikit-learn 1.6). How many output columns does that one input column produce?
- aTwo, with the third level implied once the other two are known
- bThree, one indicator column per distinct level observed during fit✓
- cOne, holding the integer position of the level inside the sorted level list
- dFour: three level indicators plus a reserved column for values not seen during fit
Explanation:A plain one-hot expansion allocates exactly one indicator column per category recorded at fit time, so three levels give three columns. Neither a compressed integer code nor an extra reserved slot appears under the default settings; those come from other options entirely.
Fe Categorical Encoding MechanicsDifficulty 2
A column with five levels is one-hot encoded with drop='first' (scikit-learn 1.6). How wide is the output block for that column, and how does a row belonging to the dropped level look?
- aFour columns; a row of the dropped level has zero in all four indicators✓
- bFour columns; a row of the dropped level carries minus one in the first indicator
- cFive columns; the first level keeps its column but it is filled with zeros everywhere
- dFour columns; rows belonging to the dropped level are removed from the output entirely
Explanation:Dropping one level removes its indicator column, leaving k-1 columns for k levels. That level is still representable: it is the unique pattern where every remaining indicator is zero, which is why the encoding stays lossless.
Fe Categorical Encoding MechanicsDifficulty 3
A table has three categorical columns: color (4 levels), is_member (2 levels), plan (3 levels). It is encoded with OneHotEncoder(drop='if_binary') in scikit-learn 1.6. How many output columns result?
- a6, because one level is dropped from every column
- b9, because the setting only changes the column names, not the width
- c8, because only the two-level column loses one of its indicators✓
- d7, because the two-level column collapses to zero columns after the drop
Explanation:The 'if_binary' rule fires only on columns that have exactly two levels, so color contributes 4 and plan contributes 3 unchanged, while is_member contributes 1 instead of 2. That gives 4+1+3 = 8 columns; dropping from every column would give 6.
Fe Categorical Encoding MechanicsDifficulty 2
A one-hot encoder is fitted on a city column containing Ankara, Istanbul and Izmir, with handle_unknown='ignore'. At transform time a row arrives with city='Bursa'. What does that row's three-column block contain?
- aThe transform stops with an error naming the unrecognised city value
- bThe indicator of the alphabetically closest known city is set to one
- cAll three indicators are set to the average value each takes in the training data
- dAll three indicators are zero, so the row carries no city information at all✓
Explanation:With unknown values ignored, the encoder simply fails to match any known level and emits an all-zero block for that feature. The row still flows through the pipeline with the right width, but every downstream model reads it as 'none of the known cities'.
Fe Categorical Encoding MechanicsDifficulty 2
A size column holds the values S, M, L and XL. An engineer applies OrdinalEncoder() with no extra arguments (scikit-learn 1.6). Which integer codes come out?
- aS=0, M=1, L=2, XL=3, because the encoder keeps the order of first appearance in the data
- bS=0, M=1, L=2, XL=3, because the encoder recognises standard clothing size names
- cL=0, M=1, S=2, XL=3, because the levels are sorted as plain strings before numbering✓
- dS=3, M=2, L=1, XL=0, because frequency ranking assigns the smallest code to the commonest level
Explanation:By default the encoder collects the distinct values and sorts them, and for text that sort is lexicographic, which puts L before M before S before XL. The resulting codes therefore carry an ordering that has nothing to do with garment size.
Fe Categorical Encoding MechanicsDifficulty 2
An engineer wants the codes for a size column to follow S < M < L < XL rather than the default ordering. In scikit-learn 1.6 they construct OrdinalEncoder(categories=[['S','M','L','XL']]). What does this argument change?
- aIt fixes the level list and its position order, so each level's code is its index in that list✓
- bIt only validates that those four levels exist, while the codes still follow the sorted order
- cIt makes the encoder learn the ordering from how strongly each level correlates with the target
- dIt rescales the codes to the 0-1 range, equalising the gap between the sizes' codes
Explanation:Passing an explicit category list replaces the automatic sorted vocabulary with the given sequence, and the code assigned to a level is simply its position there. That is the only supervision the encoder has about ordering, since it never looks at the target.