EZ

Eduzan

Learning Hub

Eduzan
Eduzan / 02 Quantitative Analysis

QTA 15: Machine Learning and Prediction

Worked examples are fully visible. Check-yourself items are study aids you can reveal one at a time.

Much of what a risk model wants to use arrives as words: a borrower lives in one region, a company sits in the technology sector. None of it can enter a model in that state, so it has to be quantified first, by a step called mapping or encoding.

Suppose a model decides whether credit card applications are accepted, and one input is the applicant’s region of residence in the US. Five categories exist: Pacific, Rocky Mountain, Midwest, Northeast, and South. The tempting shortcut is one variable set to 0 for Pacific, 1 for Rocky Mountain, 2 for Midwest, 3 for Northeast, and so on. That is wrong, since it asserts an ordering the categories do not have.

The correct treatment gives each category its own 0-1 dummy variable. For any applicant the dummy matching the region takes the value 1 and the four that do not apply take the value 0. That pattern is known as one-hot encoding.

The dummy variable trap

Where a model carries an intercept alongside a full set of dummy variables, the dummies sum to a column of ones and reproduce the intercept. This is the dummy variable trap, and no unique best-fit solution then exists. Regularization picks the solution whose dummy coefficients are smallest.

When the categories have a natural order

Some categorical data does carry a genuine ranking, in which case the variable is ordinal. Company size recorded as small, medium or large is the standard case, and one dummy variable carries it honestly: 0 for small firms, 1 for midsize firms, 2 for large firms.

Check yourself
Fund objective is coded 0 for money market, 1 for bonds, 2 for equities. Credit rating is coded 0 for junk, 1 for investment grade, 2 for prime. Which coding is acceptable?
Only the credit rating, whose categories carry a real ranking that an ordinal code records faithfully. Fund objective has no ordering, so it needs one-hot encoding into three dummies.
End of lesson.