DEV Community

Cover image for Understanding Data Distributions and Their Impact on Data Science
Barbara Morara
Barbara Morara

Posted on

Understanding Data Distributions and Their Impact on Data Science

When you first start learning data science, there are some areas like code, machine learning algorithms, and visualization tools that might draw your attention. However, one thing to note from all of this is data distribution.

Knowing about the data distribution will help you make informed decisions while cleaning data, visualizing, performing statistical analysis, and training the machine learning algorithm. Prior to training a machine learning algorithm, it is advisable to get acquainted with data distribution.

In this article, we will be discussing what data distributions are, why are they important, and also how we can visualize them using examples in Python.

What It A Data Distribution?

It is a way through which data in a dataset is described in terms of:

  • Where the values cluster
  • Is it uniformly distributed or not?
  • Outliers in the data
  • Symmetry in the distribution or skewness in it

Imagine a class room setting where students write an exam in mathematics. If most of the students have scored between 70 and 80 marks, then the distribution is clustered around these values. Also, if a few students have extremely low or high scores, then the distribution changes.
Getting this insight is crucial for data scientists before analyzing the dataset.

Importance of Data Distribution

It is crucial to know data distribution as it will help:

  • Pick appropriate statistical methods
  • Identify outliers
  • Manage missing values
  • Figure out if data should be transformed
  • Use the correct machine learning algorithms
  • Boost model performance

Lack of knowledge about data distribution leads to incorrect results and predictions.

Types of Data Distributions

1. Normal Distribution
Normal distribution is among the most common distributions in statistics.
It is characterized by a bell-shaped graph where:

  • Values tend to cluster around the center.
  • Mean, median, and mode are approximately equal.
  • Frequencies decline while moving away from the center.

Some examples include:

  • Height of people
  • IQ score distribution
  • Random measurement error

2. Skewed Distribution
Skewed distribution does not have symmetry.
There are two subtypes:

Right-Skewed (Positive Skew)
The majority of values are low while there are a few high values.
Examples:

  • Income
  • Housing prices
  • Online spending

Left-Skewed (Negative Skew)
Values are mostly high while there are few low values.
Examples:

  • Exam grade distribution after an easy test
  • Consumer satisfaction

3. Uniform Distribution
A uniform distribution is where all values have the same probability.
Example:

  • Rolling a dice.

Any number from 1 to 6 is equally likely to show up.

4. Bimodal Distribution
Bimodal distribution has two peaks.
It usually happens in case data is drawn from two populations.
Example:

  • Height distribution of male and female students.

Measuring Distribution with Statistics

Besides visualization, we can summarize distributions using statistical measures.

Mean
The average value.

import numpy as np

data = [12, 15, 18, 20, 25]

print(np.mean(data))
Enter fullscreen mode Exit fullscreen mode

Median
The middle value after sorting the data.

import numpy as np

data = [12, 15, 18, 20, 25]

print(np.median(data))
Enter fullscreen mode Exit fullscreen mode

Median comes in handy in the case of outliers since it is not sensitive to extreme data points.

Standard Deviation

Standard deviation shows how much the data is spread out.

import numpy as np

data = [12, 15, 18, 20, 25]

print(np.std(data))
Enter fullscreen mode Exit fullscreen mode

Small standard deviation – data points are closely packed together.
Large standard deviation – data points are more spread out from the mean.

Skewness Detection

In Python, Pandas provides an easy way to calculate skewness.

import pandas as pd

data = pd.Series([2, 3, 4, 5, 6, 20])

print(data.skew())
Enter fullscreen mode Exit fullscreen mode

Positive value → Right-skewed
Negative value → Left-skewed
Near zero → Approximately normal

Why Data Distribution Is Important for Machine Learning?

Most of the machine learning models work with data which is distributed in a particular way.

For instance:

  • Linear regression works better with approximately normally distributed variables.
  • Logistic regression is positively influenced by good behavior of input features.
  • Naive bayes assumes probability distribution in many cases.
  • Some clustering and anomaly detection methods depend on distribution assumptions.

When your data is highly skewed, model accuracy will likely decrease.

Non-Normal Data Handling Techniques

What should be done when your data doesn't follow a normal distribution? Don't panic – here are several options:

  • Remove or investigate potential outliers.
  • Apply transformation – logarithmic, square root, etc.
  • Normalize or scale the data.
  • Use algorithms which are less sensitive to distribution of data.

The most effective depends on your data and problem to solve.

Best Practices

Before implementing a machine learning algorithm, do the following things:

  • Investigate your data using histograms or box plots.
  • Detect skewness and outliers.
  • Calculate summary statistics.
  • Understand whether your data fulfills the requirements of your model.
  • Apply transformations if required

It is crucial to have an understanding of how data is distributed for any data scientist. The knowledge allows you to understand better your data set, apply proper statistical methods, and develop machine learning algorithms effectively.

Always take some time to explore your data before starting with training models. In five minutes, you may get valuable information about your dataset that could remain hidden from you otherwise. "Knowing your data before making your model know it."

Be it customer analytics, sales forecast, or AI solutions development; understanding data distribution would help you to make better decisions.

Top comments (0)