By the end of this lesson, you will be able to:
:information_source: Definition: Descriptive statistics helps us understand and summarize data in a meaningful way. It transforms raw numbers into useful information!
Descriptive statistics helps you:
:memo: Types of Descriptive Statistics:
- Measures of central tendency (mean, median, mode)
- Measures of variability (range, variance, standard deviation)
- Percentiles and quartiles
- Tables and graphs
Today, we'll focus on the three measures of central tendency!
The mean is what most people call the "average." You calculate it by adding all values together and dividing by how many values you have.
:bulb: Formula: Mean = Sum of all values / Number of values
Example: Finding the Mean
Let's find the mean of these numbers:
2,6,4,7,8,9
Step One: Add all numbers: 2 + 6 + 4 + 7 + 8 + 9 = 36 Step 2: Count the numbers: 6 numbers total Step 3: Divide: 36 / 6 = 6.0
Answer: The mean is 6.0! :white_check_mark:
Using Python to Calculate Mean
Python makes this even easier with NumPy's
mean()
method:python
import numpy as np number = [2,6,4,7,8,9] x = np.mean(number) print(x)
Expected output:
output6.0
This code calculates the mean automatically!
:dart: Median (Middle Value)
The median is the middle value when you arrange all numbers from smallest to largest. It splits your data into two equal halves!
Finding the Median with Odd Numbers
When you have an odd number of values, the median is simply the middle one:
2,2,4,5,7,8,11
The median is 5 (the 4th number in this 7-number list).
Finding the Median with Even Numbers
When you have an even number of values, take the average of the two middle numbers:
1,3,3,6,7,9,11,14
The two middle numbers are 6 and 7, so: Median = (6 + 7) / 2 = 6.5
Using Python to Calculate Median
NumPy's
median()
method handles both odd and even cases automatically:python
number1 = [2,2,4,5,7,8,11] med1 = np.median(number1) number2 = [1,3,3,6,7,9,11,14] med2 = np.median(number2) print("Odd number:",med1) print("Even number:",med2)
Expected output:
outputOdd number: 5.0 Even number: 6.5
Python automatically finds the median for both odd and even lists!
:trophy: Mode (Most Common Value)
The mode is the value that appears most often in your dataset. Think of it as the "most popular" number! note Important Facts about Mode:
1, 3, 3, 6, 7, 8, 9
The mode is 3 because it appears twice (more than any other number).
SciPy's mode()
method finds the most common value:
from scipy import stats
number = [1,3,3,6,7,8,9]
x = stats.mode(number)
print(x)
Expected output:
ModeResult(mode=array([3]), count=array([2]))
The output shows:
To get only the mode number without the count:
print(x.mode)
Expected output:
3
This gives you just the mode value!
You've learned three powerful ways to describe data:
Statistic | What it tells you | When to use it |
---|---|---|
Mean | The average value | When you want the typical value |
Median | The middle value | When you have outliers or extreme values |
Mode | The most common value | When you want to know what's most popular |
:bulb: Remember: Each statistic tells a different story about your data. Using all three gives you a complete picture!
:movie_camera: Video
:emoji: AI Prompt
Code with AI: Try using AI to work with descriptive statistics.
Prompts:
- "Help me calculate the mean, median, and mode of this dataset using Python."
- "Write code to find the standard deviation and variance of a numerical dataset."
- "Show me how to create a summary of descriptive statistics for my dataset including quartiles and range."
- "Generate code to identify and handle outliers in my dataset using statistical methods."
:dart: Practice Time!
Try these challenges to test your understanding:
- Calculate by Hand: Find the mean, median, and mode of: [5, 2, 8, 2, 9, 5, 2]
- Python Practice: Use NumPy and SciPy to verify your answers from challenge 1
- Real Data: Collect 10 test scores from your class and calculate all three statistics
- Think Critically: Which statistic (mean, median, or mode) would be best for:
- Describing typical house prices in a neighborhood?
- Finding the most popular ice cream flavor?
- Reporting class test scores fairly? note Hint for Challenge One: