0% found this document useful (0 votes)
8 views78 pages

Machine Learning Basics: QA & Profiling

This document outlines Part 1 of a 4-Part series on machine learning, focusing on QA and data profiling. It covers essential topics such as data quality assurance, univariate and multivariate profiling, and the importance of understanding variable types. The course is designed for analysts and BI professionals, emphasizing conceptual understanding over coding skills.

Uploaded by

Lucky Thien Than
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views78 pages

Machine Learning Basics: QA & Profiling

This document outlines Part 1 of a 4-Part series on machine learning, focusing on QA and data profiling. It covers essential topics such as data quality assurance, univariate and multivariate profiling, and the importance of understanding variable types. The course is designed for analysts and BI professionals, emphasizing conceptual understanding over coding skills.

Uploaded by

Lucky Thien Than
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MACHINE LEARNING FOR BI

PART 1:

QA & DATA PROFILING

With Expert ML Instructor Josh MacCarty

*Copyright Maven Analytics, LLC


ABOUT THIS SERIES

This is Part 1 of a 4-Part series designed to help you build a deep, foundational understanding of
machine learning, including data QA & profiling, classification, forecasting and unsupervised learning

PART 1 PART 2 PART 3 PART 4


QA & Data Profiling Classification Regression & Forecasting Unsupervised Learning

*Copyright Maven Analytics, LLC


COURSE OUTLINE

1 ML Intro & Landscape Machine Learning introduction, definition, process & landscape

Tools to explore data quality (variable types, empty values, range &
2 Preliminary Data QA count calculations, table structure, left/right censored data, etc.)

Tools to understand individual variables (distribution,


3 Univariate Profiling histograms & kernel densities, data profiling metrics, etc.)

Tools to understand multiple variables (kernel densities, violin &


4 Multivariate Profiling box plots, correlation, variance, etc.)

*Copyright Maven Analytics, LLC


SETTING EXPECTATIONS

This is NOT a coding/programming course; it’s about introducing and


demystifying essential machine learning topics
• Our goal is to break down complex techniques using simple and intuitive explanations and demos

We’ll focus on tools commonly applied to business intelligence use cases


• We’ll focus on techniques like data profiling, linear/logistic regression, forecasting, and unsupervised
learning, but will not cover some more advanced or specialized techniques (deep learning, NLP, etc.)

We’ll use Microsoft Excel as a tool to help explain key concepts


• Excel’s intuitive, visual interface allows us to expose the nuts and bolts of each technique to
understand HOW and WHY these algorithms work (rather than simply running lines of code)

You do NOT need a math or stats background to take this course


• We’ll cover the basics as needed, but won’t dive deep into statistics or econometric theory
SETTING EXPECTATIONS

Who this is for: Who this is NOT for:

• Analysts or BI professionals looking to • Senior data professionals looking to


transition into a ML/data science role master advanced topics in ML/AI

• Students looking to develop a deep • Students looking for a hands-on


conceptual understanding of core coding course or bootcamp (i.e.
machine learning topics python/R)

• Anyone who wants to understand • Anyone who would rather copy and
WHEN, WHY, and HOW to deploy paste code than become fluent in the
machine learning tools & techniques underlying algorithms
ML INTRO & LANDSCAPE

*Copyright Maven Analytics, LLC


INTRO TO MACHINE LEARNING (ML)

MACHINE LEARNING [ muh-sheen-lur-ning ]

noun

1. The capacity of a computer to process and evaluate data beyond


programmed algorithms, through contextualized inference*

Using statistical models to find patterns and make predictions

*[Link]
COMMON ML QUESTIONS

Which customers are most What will sales look like for What patterns do we see in
likely to churn next month? the next 12 months? terms of product cross-selling?

How can we use online When we adjusted tactics Which product is customer X
customer reviews to monitor last month, did we drive any most likely to purchase next?
changes in sentiment? incremental revenue?
WHEN IS ML THE RIGHT FIT?

• Machine Learning is a natural


extension of data profiling and basic
visual analysis

Machine Learning • ML is required when the underlying


Complexity data or analysis is too complex for
of analysis basic data profiling (i.e. visualizing
Multivariate relationships between 3+ variables)

• Machine Learning is ideal for finding


Univariate optimal solutions that would be
impossible or impractical to derive
through human trial-and-error
Complexity of data
THE MACHINE LEARNING PROCESS

Building models • ML models are only as good as


(the “fun” stuff) the data they are built on
(“garbage in, garbage out”)

• Data prep & QA happens behind


the scenes, but typically accounts
for the majority (80%+) of the
Data Prep, QA & Profiling
machine learning workflow
(the boring but really, really,
REALLY important stuff)
• While it’s tempting to start with
the “fun” stuff, data prep and QA
skills are absolutely critical!
MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Quality Assurance (QA) is about preparing & cleaning data prior to analysis. We’ll cover common QA topics
including variable types, empty/missing values, range & count calculations, censored data, etc.
MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Univariate profiling is about exploring individual variables to build an understanding of your data. We’ll cover
common topics like normal distributions, frequency tables, histograms, etc.
MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Multivariate profiling is about understanding relationships between multiple variables. We’ll cover common
tools for exploring categorical & numerical data, including kernel densities, violin & box plots, scatterplots, etc.
MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Machine learning is a natural extension of multivariate profiling, and uses statistical models and methods to
answer questions which are too complex to solve using simple visual analysis or trial-and-error
MACHINE LEARNING LANDSCAPE

MACHINE LEARNING

Supervised Learning Unsupervised Learning Advanced Topics

Clustering/Segmentation
Classification Regression Reinforcement Learning
K-Means (Q-learning, deep RL, multi-armed-bandit, etc.)

K-Nearest Neighbors Least Squares Outlier Detection


Natural Language Processing
Naïve Bayes Linear Regression Markov Chains (Latent Semantic Analysis, Latent Dirichlet Analysis,
relationship extraction, semantic parsing, contextual
Logistic Regression Forecasting word embeddings, translation, etc.)
Matrix factorization, principal components, factor
analysis, UMAP, T-SNE, topological data analysis,
Sentiment Analysis Non-Linear Regression
advanced clustering, etc.
Computer Vision
Monte Carlo (Convolutional neural networks, style translation, etc.)
Random forest, support
vector machines, gradient LASSO/RIDGE, state-
boosting, neural space, advanced Deep Learning
nets/deep learning, etc. generalized linear (Feed Forward, Convolutional, RNN/LSTM, Attention,
methods, VAR, DFA, etc. Deep RL, Autoencoder, GAN. etc.)
PRELIMINARY DATA QA

*Copyright Maven Analytics, LLC


MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Quality Assurance (QA) is about preparing & cleaning data prior to analysis. We’ll cover common QA topics
including variable types, empty/missing values, range & count calculations, censored data, etc.
PRELIMINARY DATA QA

Data QA (otherwise known as Quality Assurance or Quality Control) is the first step in
the analytics and machine learning process; QA allows you to identify and correct
underlying data issues (blanks, errors, incorrect formats, etc.) prior to analysis

TOPICS WE’LL COVER: COMMON USE CASES:


• Minimizing the risk of drawing false conclusions or
Variable Types Empty Values misunderstanding your data

• Confirming that dates are properly formatted for


analysis (as date values, not text strings)
Range Calculations Count Calculations
• Replacing blanks or errors with appropriate values
to prevent summarization errors
Table Structures Left/Right Censors
• Calculating ranges (max & min) to spot-check for
outliers or unexpected values
PRELIMINARY DATA QA

POP QUIZ: When should you QA your data?

EVERY. SINGLE. TIME.


(no exceptions!)
WHY IS QA IMPORTANT?

As an analyst, Preliminary Data QA will help you answer questions like:

Are there any missing or Was the data our client Is there any risk that the Are there any outliers
empty values in the data captured from the online data capture process was that might skew the
shared by the HR team? survey encoded properly? biased in some way? results of our analysis?
VARIABLE TYPES

Variable types give us information about our variables


Variable Types
• January 1, 2000 as a number simply displays a date
• January 1, 2000 as a date implies a set of information we can use (first day of
Empty Values the year, winter, Saturday, weekend, etc.) all of which can be used to build strong
machine learning models

Range Calculations
Common variable types include:

Count Calculations Numeric Discrete Date


• Customer count • Count • 1/1/2020

Ordinal Categorical Complex


Left/Right Censored • Small, Medium, Large • Gender • 4 + 2i

Interval Nominal Logical


• Temperature • Nationality • True/False
Table Structure
Ratio Binary Monetary
• Weight • Yes/No • $4.50
VARIABLE TYPES

Understanding variable types is fundamental to the machine


Variable Types
learning process, and can help avoid common QA issues, including:
• Numeric variables formatted as characters or strings, preventing proper
Empty Values aggregation or analysis
• String/character variables formatted as numeric, preventing proper text-
based operations
Range Calculations
• Values that Less obvious cases like variables that are re-coded from raw
values to buckets (surveys)
Count Calculations
Here we’re formatting zip codes (which will never be
analyzed as values), as a numeric rather than string

Left/Right Censored

When we talk about variables, we might also refer to them


as metrics, KPIs, dimensions, or columns. Similarly, we may
Table Structure use rows, observations, and records interchangeably
EMPTY VALUES

Variable Types Investigating empty values, and how they are recorded in your data,
is a prerequisite for every single analysis
Empty Values
Empty values can be recorded in many ways (NA, N/A, #N/A, NaN,
Null, “-”, “Invalid”, blank, etc.), but the most common mistake is
Range Calculations turning empty numerical values into zeros (0)

Count Calculations

Left/Right Censored

Average Age = 28.6 Average Age = 35.8


Table Structure
EMPTY VALUES

Empty values can be handled in 3 ways: keep, remove, or impute


Variable Types
• Keep empty or zero values if you are certain that they are accurate and
meaningful (i.e. no sales of a product on a specific date)
Empty Values
• Remove empty values if you have a large volume of data and can confirm that
there is no pattern or bias to the missing values (i.e. all sales from a specific
product category are missing)
Range Calculations
• Impute (substitute) empty values if you can accurately populate the data or if
you are working with limited data and can use statistical methods (mean,
conditional mean, linear interpolation, etc.) without introducing bias
Count Calculations

For a missing Units Sold value,


you would likely remove the row
Left/Right Censored unless you are certain that an
empty value represents 0 sales

Table Structure
For a missing Retail Price, you would
likely be able to impute the value
since you know the product name/ID
RANGE CALCULATIONS

Variable Types One of the simplest QA tools for numerical variables is to calculate
the range of values in a column (minimum and maximum values)

Empty Values Range calculation is a helpful tool to understand your variables,


confirm that ranges are realistic, and identify potential outliers
Range Calculations
Is there a clear lower or upper limit
min(Age) = 18 (i.e. 18+ or capped at 65)?
Count Calculations max(Age) = 65

min(Income) = 0 Is your variable transformed to a standard


Left/Right Censored max(Income) = 100 max/min scale (i.e. 1-10, 0-100)?

min(height) = -10
max(height = 10 Is your variable normalized around
Table Structure a central value (i.e. 0)?
COUNT CALCULATIONS

Count calculations help you understand the number of records or


Variable Types
observations that fall within specific categories, and can be used to:
• Identify categories you were not expecting to see
Empty Values • Begin understanding how your data is distributed
• Gather knowledge for building accurate ML models (more on this later)

Range Calculations
Distinct counts can be particularly useful for QA, and help to:
• Understand the granularity or “grain” of your data
Count Calculations
• Identify how many unique values a field contains
• Ensure consistency by identifying misspellings or categorization errors
which might otherwise be difficult to catch (i.e. leading or trailing spaces)
Left/Right Censored

PRO TIP: For numerical variables with many unique values (i.e. long decimals), use a
Table Structure histogram to plot frequency based on custom ranges or “bins” (more on that soon!)
LEFT/RIGHT CENSORED

Variable Types
When data is left or right censored, it means that due to some
circumstance the min or max value observed is not the natural
minimum or maximum of that metric
Empty Values • This can be difficult to spot unless you are aware of how the data is being
recorded (which means it’s a particularly dangerous issue to watch out for!)

Range Calculations Left Censored Right Censored

Count Calculations

Left/Right Censored

Table Structure
Mall Shopper Survey Results Ecommerce Repeat Purchase Rate
Only tracks shoppers over the age of 18 due to legal Sharp drop as you approach the current date has nothing to do
reasons, so anyone under 18 is excluded (even though with customer behavior, but the fact that recent customers
there are plenty of mall shoppers under 18) haven’t have the opportunity or need to repurchase yet
TABLE STRUCTURE

Variable Types Table structures generally come in two flavors: long or wide

Long Table Wide Table


Empty Values

Range Calculations

PIVOT

Count Calculations
UNPIVOT

Left/Right Censored

Pivoting is the process of adjusting a table from


long to wide by transforming rows into columns,
Table Structure and Unpivoting is the opposite (wide to long)
TABLE STRUCTURE

Long tables typically contain a single, distinct column for each field (Date,
Variable Types
Product, Category, Quantity, Profit, etc.)
• Easy to see all available fields and variable types
Empty Values • Great for exploratory data analysis and aggregation (i.e. PivotTables)

Range Calculations Wide tables typically split the same metric into multiple columns or
categories (i.e. 2018 Sales, 2019 Sales, 2020 Sales, etc.)
• Typically not ideal for human readability, since wide tables may contain thousands
Count Calculations of columns (vs. only a handful if pivoted to a long format)
• Often (but not always) the best format for machine learning model input
Left/Right Censored • Great format for visualizing categorical data (i.e. sales by product category)

Table Structure There’s no right or wrong table structure; each type has strengths & weaknesses!
CASE STUDY: PRELIMINARY QA

THE You’ve just been hired as a Data Analyst for Maven Market, a local grocery
SITUATION store looking for help with basic data management and analysis.

The store manager would like you to conduct some analyses on product
THE inventory and sales, but the data is a mess.
ASSIGNMENT You’ll need to explore the data, conduct a preliminary QA, and help clean it up
to prepare the data for further analysis.

1. Look at common data profiling metrics to identify potential issues


THE
2. Take note of any issues you find in the product inventory sample
OBJECTIVES
3. Correct the issues to prepare the data for further analysis
BEST PRACTICES: PRELIMINARY QA

Review all fields to ensure that variable types are configured for proper
analysis (i.e. no dates formatted as strings, text formatted as values, etc.)

Remember that NA and 0 do not mean the same thing! Think carefully about
how to handle missing data and the impact it may have on your analysis

Run basic diagnostics like Range, Count, and Left/Right Censored checks
against all columns in your data set...every time

Understand your table structure before conducting any analysis to reduce the
risk of double counting, inaccurate calculations, omitted data, etc.
UNIVARIATE PROFILING

*Copyright Maven Analytics, LLC


MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Univariate profiling is about exploring individual variables to build an understanding of your data. We’ll cover
common topics like normal distributions, frequency tables, histograms, etc.
UNIVARIATE PROFILING

Univariate profiling is the next step after preliminary QA; think of univariate profiling as
conducting a descriptive analysis of each variable by itself

TOPICS WE’LL COVER: COMMON USE CASES:


• Developing a deeper understanding of the fields
Categorical you’re working with (outliers, distribution, etc.)
Categorical Variables
Distributions
• Preparing to build ML models (necessary for
Histograms & Kernel selecting the correct model type)
Numerical Variables
Densities
• Exploring individual variables before conducting a
deeper multivariate analysis
Normal Distribution Data Profiling
CATEGORICAL VARIABLES

VARIABLE TYPES
Categorical Variables

Categorical CATEGORICAL NUMERICAL


Distributions

Categorical variables contain categories as values, instead of numbers


Numerical Variables (i.e. Product Type, Customer Name, Country, Month, etc.)
• Categorical fields are exceptionally important for data analysis, and are typically
Histograms & used as dimensions by which we filter or “cut” numerical values (i.e. sales by store)
Kernel Densities • Many types of predictive models are used to predict categorical dependent
variables, or “classes” (more on that later!)
Normal Distribution

Terms like discrete, categorical, multinomial, and classes may all be used interchangeably.
Binary is a special type of categorical variable which takes only 1 of 2 cases: true for false (or 1
Data Profiling or 0) and is also known as a logical variable or a binary flag
DISCRETIZATION

Discretization is the process of creating a new categorical variable from an


Categorical Variables existing numerical variable, based on the values of the numerical variable

Categorical
Distributions

Numerical Variables
Discretization Rules:
If Price <100 then Price Level = Low
Histograms & If Price >=100 & Price <500 then Price Level = Med
Kernel Densities If Price >=500 then Price Level = High

Normal Distribution

Data Profiling
NOMINAL VS. ORDINAL VARIABLES

VARIABLE TYPES
Categorical Variables

Categorical CATEGORICAL NUMERICAL


Distributions

Numerical Variables NOMINAL ORDINAL

Histograms &
Kernel Densities
There are two types of categorical variables: nominal and ordinal

Normal Distribution • Nominal variables contain categories with no inherent logical rank, which can be
re-ordered with no consequence (i.e. Product Type = Camping, Biking or Hiking)

• Ordinal variables contain categories with a logical order (i.e. Size = Small, Medium,
Data Profiling Large), but the interval between those categories has no logical interpretation
CATEGORICAL DISTRIBUTIONS

Categorical Variables Categorical distributions are visual and/or numeric representations of


the unique values a variable contains, and how often each occurs
Categorical
Distributions
Common categorical distributions include:
Numerical Variables • Frequency tables: Show the count (or frequency) of each distinct value
• Proportions tables: Show the count of each value as a % of the total

Histograms & • Heat maps: Formatted to visualize patterns (typically used for multiple variables)
Kernel Densities
Understanding categorical distributions will help us gather knowledge for
Normal Distribution building accurate machine learning models (more on this later!)

Data Profiling
CATEGORICAL DISTRIBUTIONS

Categorical Variables
Section Distribution:
Camping Biking
Categorical Frequency table
14 6
Distributions
Camping Biking
Proportions table
Numerical Variables 70% 30%

Histograms &
Kernel Densities Size & Section Distribution:
Camping Biking

S 6 4
Normal Distribution Heat Map
L 8 2

Data Profiling
NUMERICAL VARIABLES

VARIABLE TYPES
Categorical Variables

Categorical CATEGORICAL NUMERICAL


Distributions

Numerical variables contain numbers as values, instead of categories


Numerical Variables
(i.e. Gross Revenue, Pageviews, Quantity, Retail Price, etc.)
• Numerical fields are typically aggregated (as a sum, count, average, max, min, etc.)
Histograms & and broken down by different dimensions or categories
Kernel Densities
• Numerical data is also known as quantitative data, while categorical data is
often referred to as “qualitative”
Normal Distribution

You may hear numeric variables described further as interval and ratio, but the distinction is trivial
and rarely makes a difference in common use cases
Data Profiling
HISTOGRAMS

Categorical Variables
Histograms are used to plot a single, discretized numerical variable

Imagine taking a numerical variable (like age), defining ranges or “bins”


Categorical (1-5, 6-10, etc.), and counting the number of observations which fall
Distributions
into each bin; this is exactly what histograms are designed to do!

Numerical Variables
Age Values:

8 29 45 8

Histograms & 25 33 37
7

Frequency
Kernel Densities 6
19 43 21 5

28 32 40 4
Normal Distribution 24 17 28 3

2
5 22 39
1
15 47 12
Data Profiling 0-10 11-20 21-30 31-40 41-50

Age Range
KERNEL DENSITIES

Categorical Variables
Kernel densities are “smooth” versions of histograms, which can help
to prevent users from over-interpreting breaks between bins

Categorical • Technical definition: “Non-parametric density estimation via smoothing”


Distributions • Intuitive definition: “Wet noodle laying on a histogram”

Numerical Variables
Age Values:

8 29 45 8

Histograms & 25 33 37
7

Frequency
Kernel Densities 6
19 43 21 5

28 32 40 4
Normal Distribution 24 17 28 3

2
5 22 39
1
15 47 12
Data Profiling 0-10 11-20 21-30 31-40 41-50

Age Range
HISTOGRAMS & KERNEL DENSITIES

Categorical Variables When to use histograms and kernel density charts:


• Visualizing how a given variable is distributed
Categorical • Providing a visual glimpse of profiling metrics like mean, mode, and skewness
Distributions
Things to watch out for:
Numerical Variables • Bin sensitivity: Bin size can significantly change the shape and ”smoothness” of a
histogram, so select a bin width that accurately shows the data distribution
• Outliers: Histograms can be used to identify outliers in your data set, but you
Histograms & may need to remove them to avoid skewing the distribution
Kernel Densities
• Sample size: Histograms are best suited for variables with many observations, to
reflect the true population distribution
Normal Distribution

PRO TIP: If your data is relatively symmetrical (not skewed), you can use Sturge’s Rule as a
Data Profiling quick “rule of thumb” to determine an appropriate number of bins: K = 1 + 3.322 log (N)
(where K = number of bins, N = number of observations)
CASE STUDY: HISTOGRAMS

THE You’ve just been promoted as the new Pit Boss at The Lucky Roll Casino.
SITUATION Your mission? Use data to help expose cheats on the casino floor.

Profits at the craps tables have been unusually low, and you’ve been asked to
THE investigate the possible use of loaded die (weighted towards specific numbers).
ASSIGNMENT Your plan is to track the outcome of each roll, then compare your results
against the expected probability distribution to see how closely they match.

1. Record the outcomes for a series of individual dice rolls


THE
2. Plot the frequency of each result (1-12) using a histogram
OBJECTIVES
3. Compare your plot against the expected frequency distribution
NORMAL DISTRIBUTION

Many numerical variables naturally follow a normal distribution, also


Categorical Variables known as a Gaussian distribution or “bell curve”
• Normal distributions are symmetrical and dense around the center, with flared out
Categorical “tails” on both ends (like a bell!)
Distributions • Normal distributions are essential to many underlying assumptions in ML, and a
helpful tool for comparing distributions or testing differences between them

Numerical Variables Symmetrical

Histograms &
Kernel Densities

Normal Distribution

Most dense around center

Data Profiling
You can find normal distributions in many real-world examples: heights, weights, test scores, etc.
NORMAL DISTRIBUTION

Categorical Variables Parabola centered


around the mean

Categorical
Distributions

1 1 𝑥−𝜇 2
Numerical Variables −
𝑒 2 𝜎
Histograms &
Kernel Densities 𝜎 2𝜋 Turn the parabola
upside down
Normal Distribution
Make the tails
flare out
Data Profiling
CASE STUDY: NORMAL DISTRIBUTION

THE It’s August 2016, and you’ve been invited to Rio de Janeiro as a Data Analyst
SITUATION for the Global Olympic Committee.

Your job is to collect demographic data for all female athletes competing in
THE
the Summer Games and determine how the distribution of Olympic athlete
ASSIGNMENT heights compares against the general public.

1. Gather heights for all female athletes competing in the 2016 Games
THE 2. Plot height frequencies using a Histogram, and test various bin widths
OBJECTIVES 3. Determine if athlete heights follow a normal distribution, or “bell curve”
4. Compare the distributions for athletes vs. the general public
DATA PROFILING

Data profiling describes the process of using statistics to describe or


Categorical Variables
summarize information about a particular variable
• Data profiling is critical for understanding variable characteristics which cannot be
Categorical
seen or easily visualized using tools like histograms
Distributions
• Data profiling communicates meaning, using simple, concise, and universally
understood metrics
Numerical Variables
Common data profiling metrics include:
Histograms & • Mode
Kernel Densities
• Mean
• Median PRO TIP: Combining visual distributions with
data profiling metrics is a powerful way to
Normal Distribution • Percentile communicate meaning in advanced analytics
• Variance
• Standard Deviation
Data Profiling
• Skewness
MODE

The mode is the most frequently observed value


Categorical Variables
• With a numerical variable (most common), it’s the general range around the highest
”peak” in the distribution
Categorical
• With a categorical variable, it’s simply the value that appears most often
Distributions

Numerical Variables
Mode of City = “Houston”

Mode of Sessions = 24
Histograms &
Kernel Densities Mode of Gender = F, M
(this is a bimodal field!)

Normal Distribution
Common uses:
Data Profiling • Understanding the most common values within a dataset
• Diagnosing if one variable is influenced by another
MODE

Categorical Variables While modes typically aren’t very useful on their own, they can provide
helpful hints for deeper data exploration
Categorical • For example, the right histogram below shows a multi-modal distribution, which
Distributions indicates that there may be another variable impacting the age distribution

Numerical Variables Single Mode (21-30) Two Modes (0-10, 41-50)

8 8
Histograms & 7 7
Kernel Densities 6 6
Frequency

Frequency
5 5
4 4
Normal Distribution 3 3
2 2
1 1

0-10 11-20 21-30 31-40 41-50 0-10 11-20 21-30 31-40 41-50
Data Profiling
Age Range Age Range
MEAN

Categorical Variables
The mean is the calculated “central” value in a discrete set on numbers
• Mean is what most people think of when they hear the word “average”, and is
calculated by dividing the sum of all values by the count of all observations
Categorical
Distributions • Means can only be applied to numerical variables (not categorical)

Numerical Variables
𝑠𝑢𝑚 𝑜𝑓 𝑎𝑙𝑙 𝑣𝑎𝑙𝑢𝑒𝑠
𝑚𝑒𝑎𝑛 =
𝑐𝑜𝑢𝑛𝑡 𝑜𝑓 𝑜𝑏𝑠𝑒𝑟𝑣𝑎𝑡𝑖𝑜𝑛𝑠
Histograms &
Kernel Densities 5,220
=
5
= 𝟏, 𝟎𝟒𝟒
Normal Distribution
Common uses:
• Making a “best-guess” estimate of a value
Data Profiling
• Calculating a central value when outliers are not present
MEDIAN

The median is the middle value in a list of values sorted from highest to
Categorical Variables
lowest (or vice versa)
• When there are two middle-ranked values, the median is the average of the two
Categorical
• Medians can only be applied to numerical variables (not categorical)
Distributions

Numerical Variables

Histograms & Median = 19.5


Kernel Densities (average of 15 and 24)

Normal Distribution

Common uses:
Data Profiling • Identifying the “center” of a distribution
• Calculating a central value when outliers may be present
PERCENTILE

Percentiles are used to describe the percent of values in a column which


Categorical Variables fall below a particular number
• If you are in the 90th percentile for height, you’re taller than 90% of the population
Categorical • If the 50th percentile for test scores is 86, half of the students scored lower (which
Distributions means 86 is also the median!)

Numerical Variables

Histograms &
Kernel Densities

Bob is the 3rd tallest in a group of 12.


75% Since he’s taller than 9 others, Bob is in
Normal Distribution
the 75th percentile for height!
Common uses:
Data Profiling • Providing context and intuitive benchmarks for how values “rank” within a sample (test
scores, height/weight, blood pressure, etc.)
VARIANCE

Variance, in simple terms, describes how thin or wide a distribution is


Categorical Variables
• Variance measures how far the observations are from the mean, on average, and
help us concisely describe a variable’s distribution
Categorical
• The wider a distribution, the higher the variance (and vice versa)
Distributions

Numerical Variables
Variance = 5

Histograms & Variance = 15


Kernel Densities
Variance = 30

Normal Distribution

Common uses:
Data Profiling
• Comparing the numerical distributions of two different groups (i.e. prices of products
ordered online vs. in store)
VARIANCE

Categorical Variables 𝑛 2
σ𝑖=1(𝑥𝑖 − 𝜇)
Categorical
Distributions 𝑛−1
Numerical Variables Calculation Steps:

1) Calculate the average of the variable


Histograms &
Kernel Densities
2) Subtract that average from the first row
Average squared
3) Square that difference distance from the mean
Normal Distribution

4) Do steps 1-3 for every row and sum it up


Data Profiling
5) Divide by the number of observations (-1)
STANDARD DEVIATION

Standard Deviation is the square root of the variance


Categorical Variables
• This converts the variance back to the scale of the variable itself
• In a normal distribution, ~68% of values fall within 1 standard deviation of the mean,
Categorical
~95% fall within 2, and ~99.7% fall within 3 (known as the “empirical rule”)
Distributions

~68% ~95% ~99.7%


Numerical Variables

Histograms &
Kernel Densities

Normal Distribution 1 s.d. 2 s.d. 3 s.d.

Common uses:
Data Profiling • Comparing segments for a given metric (i.e. time on site for mobile users vs. desktop)
• Understanding how likely certain values are bound to occur
SKEWNESS

Categorical Variables Skewness tells us how a distribution varies from a normal distribution
• This is commonly used to mathematically describe skew to the left or right
Categorical
Distributions
Left skew Normal Distribution Right skew

Numerical Variables

Histograms &
Kernel Densities

Normal Distribution

Common uses:
Data Profiling
• Identifying non-normal distributions, and describing them mathematically
BEST PRACTICES: UNIVARIATE PROFILING

Make sure you are using the appropriate tools for profiling categorical
variables vs. numerical variables

Distributions are a great way to quickly and visually explore variables

QA still comes first! Profiling metrics are important, but can lead to
misleading results without proper QA (i.e. handling outliers or missing values)

One single distribution, visualization, or metric isn’t enough to fully


understand a variable; always explore your data from multiple angles
MULTIVARIATE DISTRIBUTIONS

*Copyright Maven Analytics, LLC


MACHINE LEARNING PROCESS

PREPARING YOUR DATA UNDERSTANDING YOUR DATA MODELING YOUR DATA

QUALITY ASSURANCE

UNIVARIATE PROFILING

MULTIVARIATE PROFILING

MACHINE LEARNING

Multivariate profiling is about understanding relationships between multiple variables. We’ll cover common
tools for exploring categorical & numerical data, including kernel densities, violin & box plots, scatterplots, etc.
MULTIVARIATE PROFILING

Multivariate profiling is the next step after univariate profiling, since single-metric
distributions are rarely enough to draw meaningful insights or conclusions

TOPICS WE’LL COVER: COMMON USE CASES:

• Exploring relationships between multiple categorical


Categorical-Categorical Categorical-Numerical
and/or numerical variables
Distributions Distributions
• Informing which specific machine learning models or
Multivariate Kernel techniques to use
Violin & Box Plots
Densities

Multivariate distributions are generally called “joint”


Numerical-Numerical Scatter Plots & distributions, and it’s clear why—it’s joining two variables
Distributions Correlation into the same distribution!
CATEGORICAL-CATEGORICAL DISTRIBUTIONS

Categorical-Categorical Categorical/categorical distributions represent the frequency of


Distributions unique combinations between two or more categorical variables

Categorical-Numerical
Distributions This is one of the simplest forms of multivariate profiling, and leverages
the same tools we used to analyze univariate distributions:
Multivariate Kernel
Densities • Frequency tables: Show the count (or frequency) of each distinct combination
• Proportions tables: Show the count of each combination as a % of the total
Violin & Box Plots • Heat maps: Frequency or proportions table formatted to visualize patterns

Numerical-Numerical Common uses:


Distributions
• Understanding product mix based on multiple characteristics (i.e. size & category)

Scatter Plots &


• Exploring customer demographics based on attributes like location, gender, etc.
Correlation
CATEGORICAL-CATEGORICAL DISTRIBUTIONS

Categorical-Categorical In this example we’re looking


Distributions at product inventory using a
distribution of two categorical Frequency
Table
Categorical-Numerical fields: Design and Size
Distributions

Multivariate Kernel We can show this joint


Densities
distribution as a simple count
(Frequency Table), as a Proportions
Table
Violin & Box Plots percentage of the total
(Proportions Table), or as a
conditionally formatted table
Numerical-Numerical
Distributions
(Heat Map)

Scatter Plots & Heat Map


Correlation
CASE STUDY: HEAT MAPS

THE You’ve just been hired by the New York Department of Transportation
SITUATION (DOT) to help analyze traffic accidents in New York City from 2019-2020

The DOT commissioner would like to understand accident frequency by time of


day and day of week, in order to support a public service campaign promoting
THE safe driving habits.
ASSIGNMENT Your role is to provide the data that she needs to understand when traffic
accidents are most likely to occur.

THE 1. Create a table to plot accident frequency by time of day and day of week
OBJECTIVES 2. Apply conditional formatting to the table to create a heatmap showing the
days and times with the fewest (green) and most (red) accidents in the sample
CATEGORICAL-NUMERICAL DISTRIBUTIONS

Categorical-numerical distributions are used for comparing numerical


Categorical-Categorical
Distributions
distributions across classes in a category (i.e. age distribution by gender)

Categorical-Numerical These are typically visualized using variations of familiar univariate


Distributions
numerical distributions, including:
Multivariate Kernel • Histograms & Kernel Densities: Show the count (or frequency) of values
Densities
• Violin Plots: Kernel density “glued” to its mirror image, and tilted on its side
• Box Plots: Like a kernel density, but formatted to visualize key statistical values
Violin & Box Plots (min/max, median, quartiles) and outliers

Numerical-Numerical Common uses:


Distributions
• Comparing key business metrics (i.e. customer lifetime value, average order size,
Scatter Plots & purchase frequency, etc.) by customer class (gender, loyalty status, location, etc.)
Correlation • Comparing sales performance by day of week or hour of day
KERNEL DENSITIES

Categorical-Categorical Remember: kernel densities are just smooth versions of histograms


Distributions
• To visualize a categorical-numerical distribution, kernel densities can be repeated
to represent each class within a particular category
Categorical-Numerical
Distributions

Multivariate Kernel Teal class has a mean of ~15 and relatively low
Densities variance (highly concentrated around the mean)

Violin & Box Plots Yellow class has a mean of ~20 and moderate
variance relative to other categories

Numerical-Numerical
Distributions Purple class has a mean of ~25, overlaps with
yellow, and has relatively high variance

Scatter Plots &


Correlation
VIOLIN PLOTS

Categorical-Categorical A violin plot is essentially a kernel density flipped vertically and


Distributions combined with its mirror image
Categorical-Numerical • Violin plots use the exact same
Distributions data as kernel densities, just
visualized slightly differently
Multivariate Kernel
Densities • These can help you visualize the
shape of each distribution, and
compare them across classes
Violin & Box Plots more clearly

Numerical-Numerical
Distributions

Scatter Plots &


Correlation
BOX PLOTS

Box plots are like violin plots, but designed


Categorical-Categorical
Distributions
to show key statistical attributes rather than
smooth distributions, including:
Categorical-Numerical
Distributions • Median
• Min & Max (excluding outliers)
Multivariate Kernel
Densities • 25th & 75th Percentiles
• Outliers
Violin & Box Plots

Box plots provide a ton of information in a


Numerical-Numerical
Distributions
single visual, and can be used to quickly
compare statistical characteristics between
Scatter Plots & classes
Correlation
LIMITATIONS OF CATEGORICAL DISTRIBUTIONS

Categorical profiling works for simple cases, but breaks down quickly
Categorical-Categorical
Distributions • Humans are pretty good at visualizing 1, 2, or maybe even 3 variables, but how
would you visualize a joint distribution for 10 variables? 100?
Categorical-Numerical
Distributions

Multivariate Kernel
Densities
?
Violin & Box Plots Categorical profiling can’t answer prescriptive or predictive questions
• Suppose you randomized several elements on your sales page (font, image, layout,
button, copy, etc.) to understand which ones drive conversions
Numerical-Numerical
Distributions • You could count conversions for individual elements, or some combinations of
elements, but categorical distribution alone can’t measure causation
Scatter Plots &
Correlation
This is when you need machine learning!
NUMERICAL-NUMERICAL DISTRIBUTIONS

Numerical-Numerical distributions are common and intuitive, but the


Categorical-Categorical
Distributions most complex mathematically

Categorical-Numerical They are typically visualized using scatter plots, which plot points along
Distributions
the X and Y axis to show the relationship between two variables
Multivariate Kernel • Scatter plots allow for simple, visual intuition: when one variable increases or
Densities decreases, how does the other variable change?
• There are many possibilities: no relationship, positive, negative, linear, non-linear,
Violin & Box Plots cubic, exponential, etc.

Numerical-Numerical Common uses:


Distributions
• Quickly visualizing how two numerical variables relate
Scatter Plots & • Predicting how a change in one variable will impact another (i.e. square footage and
Correlation house price, marketing spend and sales, etc.)
CORRELATION

Univariate profiling metrics aren’t much help in the multivariate world;


Categorical-Categorical
Distributions we now need a way to describe relationships between variables

Categorical-Numerical Correlation is the most common multivariate profiling metric, and is


Distributions
used to describe how a pair of variables are linearly related
Multivariate Kernel • In other words: for a given row, when one variable’s observation goes above its mean,
Densities does the other variable’s observation also go above its mean (and vice versa)?

Violin & Box Plots

Numerical-Numerical
Distributions

Scatter Plots &


Correlation
No correlation Positive correlation Strong positive correlation
CORRELATION

Correlation is an extension of variance


Categorical-Categorical
Distributions • Think of correlation as a way to measure the variance of both variables at one time
(called “co-variance”), while controlling for the scales of each variable
Categorical-Numerical
Distributions
Variance formula Correlation formula

Multivariate Kernel
Densities
σ𝑛𝑖=1(𝑥𝑖 − 𝜇) 2 σ𝑛𝑖=1(𝑥𝑖 − 𝑥)(𝑦𝑖 − 𝑦)
Violin & Box Plots 𝑛−1 (𝑛 − 1)𝑠𝑥 𝑠𝑦
Numerical-Numerical
Distributions • Here we multiply variable X’s difference from its mean with variable Y’s difference
from its mean, instead of squaring a single variable (like we do with variance)
Scatter Plots &
Correlation • Sx and Sy are the standard deviations of X and Y, which puts them on the same scale
CORRELATION VS. CAUSATION

Categorical-Categorical

CORRELATION
Distributions

Categorical-Numerical
Distributions

Multivariate Kernel
Densities DOES NOT IMPLY
Violin & Box Plots

Numerical-Numerical
Distributions CAUSATION
Scatter Plots &
Correlation
CORRELATION VS. CAUSATION

Categorical-Categorical

Drowning Deaths
Distributions

Categorical-Numerical
Distributions

Multivariate Kernel
Densities
Ice Cream Cones Sold

Violin & Box Plots Consider the scatter plot above, showing daily ice cream sales and
drowning deaths in a popular New England vacation town
Numerical-Numerical • These two variables are clearly correlated, but do ice cream cones CAUSE people to
Distributions drown? Do drowning deaths CAUSE a surge in ice cream sales?

Scatter Plots &


Correlation
Of course not, because correlation does NOT imply causation!
So what do you think is really going on here?
PRO TIP: VISUALIZING A THIRD DIMENSION

Categorical-Categorical Scatter plots show two dimensions by default (X and Y), but using
Distributions symbols or color allows you to visualize additional variables and
expose otherwise hidden patterns or trends
Categorical-Numerical
Distributions

Multivariate Kernel
Densities

Violin & Box Plots

Numerical-Numerical
Distributions

Visualizing more than 3-4 dimensions is beyond human capability.


Scatter Plots & This is where you need machine learning!
Correlation
CASE STUDY: CORRELATION

THE You’ve just landed your dream job as a Marketing Analyst at Loud & Clear, the
SITUATION hottest ad agency in San Diego.

Your client would like to understand the impact of their digital media spend, and
THE how it relates to website traffic, offline spend, site load time, and sales.
ASSIGNMENT Your role is to collect and visualize these metrics at the weekly-level in order to
begin exploring the relationships between them.

1. Gather weekly spend, traffic, website, and sales data


THE 2. Create a scatterplot to visualize any two given variables
OBJECTIVES 3. Compare the relationship between Digital Media Spend and each variable
4. What patterns do you see, and how would you interpret them?
BEST PRACTICES: MULTIVARIATE PROFILING

Univariate profiling is a great start, but multivariate profiling is necessary


when working with more than one variable (pretty much always)

Understand the types of variables you’re working with (categorical vs.


numerical) to determine which profiling and visualization techniques to use

Use categorical variables to filter or “cut” your data and quickly compare
profiling metrics or distributions across classes

Remember that correlation does not imply causation, and that variables can
be related without one causing a change in the other
LOOKING AHEAD

CONGRATULATIONS!
Now that you’ve completed Part 1: QA & Data Profiling, you should have a strong grasp of QA
techniques, univariate & multivariate distributions, and common data profiling metrics.

In Part 2 we’ll dive into supervised machine learning and explore powerful classification
techniques like K-Nearest Neighbors, Naïve Bayes, Decision Trees, Logistic Regression,
Sentiment Analysis and more.

PART 1 PART 2 PART 3 PART 4


QA & Data Profiling Classification Regression & Forecasting Unsupervised Learning

You might also like