Python Tutorial : Feature engineering and overfitting
Skills:
ML Pipelines80%
Key Takeaways
This video tutorial covers feature engineering and overfitting in machine learning using Python, discussing techniques such as label encoding, one hot encoding, and feature selection using the select K best algorithm.
Full Transcript
feature engineering uses domain knowledge and common sense to describe an object with numbers although adding more features can improve performance it can also increase the risk of overfitting in this lesson you will learn more about this interesting trade of sometimes the raw data cannot fit into the form of a table for example consider electrocardiogram or ECG traces for a number of individuals each ECG trace is a time series possibly of variable length that cannot fit in one cell of a table instead in the datasets shown here experts extracted over 250 one-dimensional numerical summaries from each ECG these range from simple summaries like heart rate to very complex properties of the signal with weird names like T wave amp all of which can be useful in detecting a medical condition known as arrhythmia even if the data are tabular some of the columns might be non numeric here is an example from the credit scoring data set the purpose of the loan takes values such as buy a new car education or retraining label encoder will map these values on to a range of numbers but the classifier is then confused it thinks that the categories have a natural ordering for example a decision tree might try to split the range in two if it splits at 4 it is putting loans for business together with loans for a microwave oven a different approach is to use one hot encoding implemented by the get dummies and us method this creates one new dummy variable for each category taking the value one for each example that falls in that category and zero otherwise you can see the first row of the data on the Left printed vertically for readability no artificial ordering is introduced how about capturing semantic similarity notice that similar categories share keywords for example all consumer loans feature the keyword buy you can count common keywords using count vectorizer from the feature extraction module first replace underscores with spaces for easier tokenization then apply the encoder using its fit transform method finally convert the resulting matrix to a data frame naming the columns using the debt feature names method of the count vectorizer object note that as we improve our feature engineering pipeline the dimension of our data frame increases the question arises how many features is too many well with more columns the algorithm has more opportunity to mistake coincidental patterns for real signal we can test this by adding columns to the data containing purely random numbers totally unrelated to the class as we add more columns on the horizontal axis overfitting kicks in accuracy improves in sample but deteriorates out-of-sample a popular solution is to add features freely and then select the best ones using some feature selection technique let's try the trick from the preview slide and augment the credit scoring data set with 100 fake variables then we use the select K best algorithm from the feature selector module to select the twenty highest scoring columns we use the chi-squared scoring method the feature selector has a fit method to fit it to the data and a dead support method that returns the index of the selected columns thankfully only a handful of fake columns remain in the selected features so remember this every decision you make in your pipeline might affect other aspects of it and in particular the risk of overfitting the following exercises confirm this inside
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/designing-machine-learning-workflows-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Feature engineering uses domain knowledge and common sense to describe an object with numbers. Although adding more features can improve performance, it can also increase the risk of overfitting. In this lesson, you will learn more about this interesting trade-off.
Sometimes, the raw data can not fit into the form of a table. For example, consider electrocardiogram (or ECG) traces for a number of individuals. Each ECG trace is a time series, possibly of variable length, that cannot fit in one cell of a table.
Instead, in the dataset shown here experts extracted over 250 one-dimensional numerical summaries from each ECG. These range from simple summaries like heart-rate to very complex properties of the signal with weird names like T-wave-amp, all of which can be useful in detecting a medical condition known as arrhythmia.
Even if the data are tabular, some of the columns might be non-numeric. Here is an example from the credit scoring dataset: the purpose of the loan takes values such as "buy a new car", "education" or "retraining". LabelEncoder will map these values onto a range of numbers.
But the classifier is then confused. It thinks that the categories have a natural ordering. For example, a decision tree might try to split the range in two. If it splits at 4, it is putting loans for business together with loans for a microwave oven!
A different approach is to use one-hot-encoding, implemented by the .get_dummies() pandas method. This creates one new dummy variable for each category, taking the value 1 for each example that falls in that category and 0 otherwise. You can see the first row of the data on the left, printed vertically for readability. No artificial ordering is introduced.
How about capturing semantic sim
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Pipelines
View skill →
🎓
Tutor Explanation
DeepCamp AI