Python Tutorial: Data distributions and transformations
Key Takeaways
The video discusses data distributions and transformations in Python, covering topics such as handling different distributions between training and test data, and transforming data to reduce the influence of outliers and achieve normality.
Full Transcript
welcome back in the previous exercises you practiced finding and handling missing values in this video we're going to discuss what it means to have different distributions between the data used to train a model and test data or future data and how and when to transform your data there is a chance that the way in which we split a data set before we send it into machine learning models can cause the training and test sets to have different distributions which introduces bias into the machine learning framework it's obvious in the illustration shown that the distributions have both different means and different variances and this will likely contribute to poor model performance you'll get to practice this concept in the exercises that follow and in Chapter two we'll introduce the best technique to avoid this problem to prepare two distributions for visualization in this lesson we'll use the two-way multiple assignment seen here as trained comma test since we aren't building models as of yet once we get into building machine learning models in the next chapter we're going to use the four-way split where we'll create a feature matrix capital X and target array Y split into train and test named here as X train X test Y train and so on notice however that the keyword arguments are exactly the same with the data set as the first argument test underscore size equal to 0.3 in this example means that the Train test split of the data will be 70% training and 30% test to create the plots you'll use the pair plot function from the Seabourn module which is always imported and aliased as SNS and returns a plot matrix of distributions and scatter plots so that takes care of what we need to cover for distributions let's move on to data transformations the left-hand side of this image depicts data that is right skewed outliers are one cause of non normality or non-gaussian behavior and transformation can reduce the influence of existing outliers the right side shows the same data after it has been transformed with the log function we'll talk about what to do if outliers still remain after any transformations in the next lesson for now our goal is to transform data from a non normal distribution to the most approximately normal one that we can as we need that for our models to perform better than they would otherwise in the exercises you'll use the box-cox function from the side pi dat stats module to perform power transformations a power transformation raises each value in the data set to a power P the table you see here this common values that can be passed to the transformation parameter lambda note that it's spelled L M B D a 0.0 is used for taking the log of X and 0.5 for the square root of x now it's finally time for you to go check out some distributions and
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/practicing-machine-learning-interview-questions-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Welcome back! In the previous exercises you practiced finding and handling missing values. In this video, we're going to discuss what it means to have different distributions between the data used to train a model and test data, or future data and how and when to transform your data.
There is a chance that the way in which we split a dataset before we send it into machine learning models can cause the training and test sets to have different distributions which introduces bias into the machine learning framework. It's obvious in the illustration shown that the distributions have both different means and different variances and this will likely contribute to poor model performance. You'll get to practice this concept in the exercises that follow and in chapter 2, we'll introduce the best technique to avoid this problem.
To prepare two distributions for visualization in this lesson, we'll use the 2-way multiple assignment seen here as train comma test since we aren't building models as of yet. Once we get into building machine learning models in the next chapter, we're going to use the 4-way split where we'll create a feature matrix capital X and target array y split into train and test named here as X_train, X_test, y_train and so on. Notice, however, that the keyword arguments are exactly the same with the dataset as the first argument. Test underscore size equal to 0.3 in this example means that the train test split of the data will be 70% training and 30% test.
To create the plots you'll use the pairplot function from the seaborn module, which is always imported and aliased as sns, and returns a plot matrix of distributions and scatterplots. So that takes care of what we need to cover for distributions
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 Maths Basics
View skill →
🎓
Tutor Explanation
DeepCamp AI