Data 198: Introduction to Real World Data Science
10/13/25: Feature Engineering & Selection
Attendance
Announcements
Today’s Instructors
Kyle Han
2nd Year
Data Science
Interests: NLP, AI/ML, Education
Sameer Rahman
2nd Year
Data Science
Interests: AI/ML, NLP, Sports Analytics, Fintech
Ice Breaker
You can only keep 3 apps on your phone…what are you keeping?
Machine Learning Pipeline
What is a Feature?
Real-world Scenario
You’re tasked with creating a model that predicts NBA player salaries
Each of these columns is a feature: measurable property of your data
If you had to make a housing prediction model, what are some features would you want for your model?
Feature Engineering
Feature Engineering
Using domain knowledge to create new, meaningful features from raw data
Gives your analysis a different perspective – uncover patterns you’d otherwise miss
Your chance to show creativity + domain expertise
Turn to your neighbor and discuss some domains you think you have a lot of expertise in
Why is this Important?
Even simple models are better with strong features
Goal: Create features with high correlations to target variable
Data Cleaning Review
First make sure that your data is clean:
Handling Missing Data as Features
Missing data can be informative
We can add a flag feature instead of just filling or dropping
Handling Categorical Data
Machine learning models need numbers, not text
2 Main Ways of Approaching categorical data:
One-Hot Encoding
Label Encoding
One-Hot Encoding
Creates a new binary column for each category
Best for nominal data with no particular order
Each row gets a 1 in the column that matches the category
pd.get_dummies(df[col])
Label Encoding
Assigns a unique integer to each category
Best for ordinal data with a clear order
from sklearn.preprocessing import LabelEncoder
Encoder = LabelEncoder()
df[‘Encoded Col’] = encoder.fit_transform(df[‘Col’])
Which of the following columns do you think should be one-hot encoded or label encoded?
Creating New Features
Oftentimes, it’s better to create new features using domain knowledge to capture otherwise unseen relationships
Housing Data:
Do some more EDA and see if you can find more linear relationships with your target variable
What could be a problem with this housing data?
The values in size and num_bedrooms are scaled totally different!
The model would incorrectly believe that the size feature is 1000x more important than the bedrooms feature.
Technique: Feature Scaling
Most of the time, we don’t want one feature to overpower all other features. Feature scaling can help normalize features to be on a similar scale.
Applications
Normalization: Scales data to a fixed range, usually 0 to 1.
Standardization: Scales data to have a mean of 0 and a standard deviation of 1 using z-scores.
Feature scaling good 👍
Feature Selection
Feature Selection
Feature Selection = process of selecting a subset of relevant features from your data
Pandas
Relational Algebra
Feature Selection Importance
Reduces Overfitting: Fewer redundant features mean the model is less likely to learn from noise.
Improves Accuracy: Removing irrelevant features can improve the model's generalization performance.
Reduces Training Time: Fewer features mean faster model training and prediction.
Improves Interpretability: Simpler models with fewer features are easier to understand.
Feature Selection Methods
Statistical Filtering
Wrapper Methods
Embedded Methods
Key Takeaways
Feature Engineering is about creating the best possible features from your raw data.
Feature Selection is about choosing the most relevant features to build simpler, faster, and more robust models.
Both are essential for building high-performing machine learning systems.
And remember GIGO: Garbage in, Garbage Out!
Worksheet!
Resources!
Game!
Attendance
Thank You!