Python Tutorial: Data distributions and transformations

DataCamp · Beginner ·🔢 Mathematical Foundations ·6y ago

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 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This video teaches how to handle different data distributions and transform data to achieve normality, which is essential for machine learning models to perform well. It covers topics such as power transformations and handling outliers.

Key Takeaways
  1. Split data into training and test sets
  2. Visualize data distributions using Seaborn
  3. Apply power transformations using the box-cox function
  4. Handle outliers and non-normality
💡 Transforming data to achieve normality is crucial for machine learning models to perform well, and power transformations can be an effective way to reduce the influence of outliers.

Related Reads

Up next
How to Open OSM Files (OpenStreetMap Data)
File Extension Geeks
Watch →