What is a feature?
- Machine Learning course
- Beginner
- Lesson 81/112
- 5 min
A feature is a measurable data column used as model input.
What is a feature?
A feature is a single measurement the model knows about an example: the house's square metres, the customer's age, the number of links in an e-mail. The model can only learn what it sees in the features.
# house: [square_m, rooms, floor, building_age]
X = np.array([[120, 3, 2, 10],
[ 85, 2, 5, 25]])Good features often make more difference than the choice of algorithm. Producing new, meaningful features with domain knowledge is called feature engineering.
Signs of a good feature
A good feature:
- Is related to the target (square metres to price).
- Is known at prediction time too: contains no information from the future.
- Has little noise and is filled in most examples.
# LEAKAGE: putting a "debt_collection_started" column in a credit risk model
# that information only appears once the loan fails; it doesn't exist at prediction timeFeatures that indirectly contain the target give great results in training and useless ones in reality; this is a kind of data leakage.
Practice Derive a feature
The first column of X is square metres and the second is the room count. Compute square metres per room, add it to X as a new column with np.column_stack, and print the new matrix's shape and its last column.
Starter code
import numpy as np
X = np.array([[120, 3], [90, 2], [150, 5]], dtype=float)
# buraya yazSample solution
import numpy as np
X = np.array([[120, 3], [90, 2], [150, 5]], dtype=float)
alan_oda = X[:, 0] / X[:, 1]
X2 = np.column_stack([X, alan_oda])
print(X2.shape)
print(X2[:, -1])Expected output
(3, 3) [40. 45. 30.]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is the most meaningful derived feature for a house price model?
- Square metres per room Correct answer
- The row number
- The owner's name
- The time of entry
Explanation: Area per room describes how spacious the house is; the others are unrelated to price.
2 Compute the area-per-room feature.
alan_oda = X[:, 0] ____ X[:, 1]
alan_oda = X[:, 0] / X[:, 1]
Explanation: Ratio features capture the relationship of two measurements in one number.
3 Match the features with the assessment.
| Term | Meaning |
|---|---|
square metres |
Related to price |
kayıt_id |
Meaningless |
satış_sonrası_değer |
Leakage |
area per room |
Derived, useful |