SciPy for Statistics (scipy.stats)

Statistics is the backbone of data analytics.

It helps us understand data behavior, identify patterns, and make informed decisions.

While NumPy provides basic statistical functions, SciPy takes statistics to the next level by offering advanced and ready-to-use statistical tools through the scipy.stats module.

This module is heavily used in :



What is scipy.stats?

scipy.stats is a SciPy submodule that provides :

It works directly with NumPy arrays, making it easy to integrate into analytics workflows.



Basic Statistical Measures

Mean, Median, and Mode

These measures help understand the central tendency of data.

import numpy as np
from scipy import stats
data = np.array([10, 12, 15, 18, 20])
print("Mean:", np.mean(data))
print("Median:", np.median(data))
print("Mode:", stats.mode(data))

#Output: 
Mean: 15.0
Median: 15.0
Mode: ModeResult(mode=np.int64(10), count=np.int64(1))

Real-Life Use :



Variance and Standard Deviation

These measure how spread out the data is.

print("Variance:", np.var(data))
print("Standard Deviation:", np.std(data))

#Output: 
Variance: 13.6
Standard Deviation: 3.687817782917155

Why This Matters

Used in :



Probability Distributions (Basic Idea)

Probability distributions describe how values are distributed.

Common Distributions


Example: Normal Distribution

from scipy.stats import norm
mean = 50
std_dev = 5
probability = norm.pdf(55, mean, std_dev)
print(probability)

#Output: 0.04839414490382867

Used in :



Correlation and Relationship Between Data

Correlation tells us how strongly two variables are related.

x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 6, 8, 10])
correlation, _ = stats.pearsonr(x, y)
print("Correlation:", correlation)

#Output: 
Correlation: 1.0

Interpretation :



Real-Life Example: Sales vs Advertising

Businesses often analyze :

Correlation helps determine whether increased marketing actually impacts sales.



Hypothesis Testing (Basic Understanding)

Hypothesis testing helps us validate assumptions using data.

Common questions :

Example: One-Sample t-test

sample = np.array([100, 102, 98, 101, 99])
t_stat, p_value = stats.ttest_1samp(sample, 100)
print("p-value:", p_value)

#Output: 
p-value: 1.0

If p-value < 0.05, the result is usually considered statistically significant.



Why Hypothesis Testing Is Important

Used in :

It helps move from assumptions to evidence-based decisions.



Common Beginner Mistakes

Statistics should always be combined with domain understanding.



Why scipy.stats Is Important in Data Analytics

It helps analysts :

Almost every serious analytics project uses statistical analysis.



Key Takeaways