DEV Community

Ephantus Macharia
Ephantus Macharia

Posted on

Statistics for Data Science

Data science is often presented as:

Python + Machine Learning + Data = Data Science
Enter fullscreen mode Exit fullscreen mode

But there is something underneath all three:

Statistics.

Machine learning can build a prediction. Python can process the data. A dashboard can make the result look beautiful.

But statistics helps you answer the most important question:

"Can I trust what the data is telling me?"


Start With Descriptive Statistics

Before predicting anything, understand what you already have.

Imagine these exam scores:

45, 50, 52, 55, 60, 62, 90
Enter fullscreen mode Exit fullscreen mode

You can summarize them using:

  • Mean → average
  • Median → middle value
  • Mode → most frequent value
  • Range → maximum − minimum
  • Variance → how spread out the data is
  • Standard deviation → typical distance from the mean

In Python:

import numpy as np

scores = [45, 50, 52, 55, 60, 62, 90]

print("Mean:", np.mean(scores))
print("Median:", np.median(scores))
print("Standard deviation:", np.std(scores))
Enter fullscreen mode Exit fullscreen mode

Why does this matter?

The mean alone can be misleading.

That 90 is pulling the average upward.

Statistics helps you notice the story hidden behind the average.


Distribution: How Is Your Data Behaving?

Data doesn't always behave nicely.

It can be:

Normal       →    
Right-skewed →     
Left-skewed  →     
Uniform      →     
Bimodal      →     
Enter fullscreen mode Exit fullscreen mode

Understanding distributions helps you decide how to analyze your data.

For example:

import matplotlib.pyplot as plt

plt.hist(scores, bins=5)
plt.xlabel("Score")
plt.ylabel("Frequency")
plt.title("Distribution of Exam Scores")
plt.show()
Enter fullscreen mode Exit fullscreen mode

Strong pointer

Always visualize your data before trusting a statistical summary.

A graph can reveal patterns that a table of numbers hides.


Probability: Measuring Uncertainty

Data science rarely deals with certainty.

Instead, we ask:

"How likely is this?"

For example:

Probability of rain = 70%
Enter fullscreen mode Exit fullscreen mode

Or in machine learning:

Probability customer will churn = 0.82
Enter fullscreen mode Exit fullscreen mode

Probability gives us a mathematical language for uncertainty.

And uncertainty is everywhere in data science.


. Hypothesis Testing

Suppose a company introduces a new website design.

The average conversion rate increases from:

5.1% → 5.8%
Enter fullscreen mode Exit fullscreen mode

Is that a real improvement?

Or could it simply be random variation?

This is where hypothesis testing comes in.

We formulate:

H₀ → No meaningful difference
H₁ → There is a difference
Enter fullscreen mode Exit fullscreen mode

Then we use an appropriate statistical test.

Common tests include:

  • t-test
  • ANOVA
  • Chi-square
  • Mann–Whitney U
  • Wilcoxon
  • Pearson correlation
  • Spearman correlation

P-Values: Don't Worship 0.05

You will often hear:

p < 0.05
Enter fullscreen mode Exit fullscreen mode

But statistics is more than checking whether a number crossed 0.05.

A p-value helps quantify how compatible the observed data are with the null hypothesis under the assumptions of the statistical test.

And remember:

A small p-value does not automatically mean the effect is important.

Always consider:

Statistical significance
        +
Effect size
        +
Confidence interval
        +
Real-world importance
Enter fullscreen mode Exit fullscreen mode

Confidence Intervals

Suppose your analysis estimates that the average delivery time is:

42 minutes
Enter fullscreen mode Exit fullscreen mode

Instead of reporting only:

42 minutes
Enter fullscreen mode Exit fullscreen mode

you might report an interval such as:

95% CI: 39–45 minutes
Enter fullscreen mode Exit fullscreen mode

The interval communicates uncertainty around the estimate.

Think of it as:

"Here is our estimate, and here is the uncertainty surrounding it."


. Correlation: When Variables Move Together

Suppose we discover:

Hours studied ↑
        ↓
Exam scores ↑
Enter fullscreen mode Exit fullscreen mode

There may be a positive relationship.

Python makes this easy:

from scipy.stats import pearsonr

correlation, p_value = pearsonr(hours, scores)

print(correlation)
print(p_value)
Enter fullscreen mode Exit fullscreen mode

But remember the golden rule:

Correlation does not prove causation.

Ice cream sales and swimming accidents might increase during summer.

That doesn't mean ice cream causes swimming accidents.

A third factor—temperature—may influence both.


Sampling: You Usually Don't Need Everyone

Imagine a country has:

50 million people
Enter fullscreen mode Exit fullscreen mode

and you want to understand consumer preferences.

You don't necessarily need to ask all 50 million.

You can study a sample.

Population
     ↓
   Sample
     ↓
Analysis
     ↓
Inference about population
Enter fullscreen mode Exit fullscreen mode

But there is a catch:

A bad sample can produce a confidently wrong conclusion.

Sampling bias is therefore a major concern in data science.


. Statistics Meets Machine Learning

Statistics isn't separate from machine learning.

They overlap everywhere.

Statistics Data Science / ML
Probability Classification probabilities
Distributions Model assumptions
Correlation Feature analysis
Sampling Train/test datasets
Confidence intervals Uncertainty
Hypothesis testing Experimentation
Regression Predictive modeling
Variance Model generalization

This is why learning statistics makes machine learning concepts much easier to understand.


The Data Scientist's Statistical Mindset

When you receive a dataset, don't immediately open your machine-learning library.

Ask:

What does each variable mean?
          ↓
What does the distribution look like?
          ↓
Are there outliers?
          ↓
How much variation exists?
          ↓
Is the sample representative?
          ↓
Are variables related?
          ↓
Could this pattern be random?
          ↓
What uncertainty exists?
          ↓
What conclusion can the data actually support?
Enter fullscreen mode Exit fullscreen mode

That mindset is more valuable than memorizing formulas.


The Statistics Toolkit

If you're learning data science, build your statistics foundation around these areas:

Descriptive Statistics

Mean • Median • Mode • Variance • Standard Deviation

Probability

Events • Conditional Probability • Bayes' Theorem

Distributions

Normal • Binomial • Poisson • Uniform

Inferential Statistics

Sampling • Confidence Intervals • Hypothesis Testing

Relationships

Correlation • Covariance • Regression

Statistical Tests

t-test • ANOVA • Chi-square • Mann–Whitney • Wilcoxon

Experimental Thinking

A/B Testing • Control Groups • Randomization • Bias


Conclusion

Statistics isn't about making data complicated.

It's about learning how to question the numbers.

When you see:

📈 Revenue increased 20%
Enter fullscreen mode Exit fullscreen mode

don't immediately celebrate.

Ask:

20% compared with what?

When you see:

🎯 Model accuracy = 95%
Enter fullscreen mode Exit fullscreen mode

ask:

95% on which dataset?

When you see:

🔗 Correlation = 0.85
Enter fullscreen mode Exit fullscreen mode

ask:

Does correlation actually explain the relationship?

And when you see:

p < 0.05
Enter fullscreen mode Exit fullscreen mode

ask:

Is the effect statistically significant, and does it actually matter?

That's the difference between reading numbers and thinking with data.

Statistics doesn't just tell you what happened. It teaches you how confident you should be in the story your data is telling.

Top comments (0)