Search Header Logo
Summer Lesson 27

Summer Lesson 27

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Hard

Created by

Robert Giordano

FREE Resource

14 Slides • 4 Questions

1

media

Lesson 27

Mean, Median, Mode, and Range

2

media

Mean, Median, and
Mode

Almost everyone is familiar with the concepts of
mean, median, and mode. These 3 statistical data
pieces are useful in analyzing datasets.

Mean: the average value of the dataset

Median: the middle value of the dataset

Mode: the most repeated value of the dataset

3

media

Sorting a List

Traditionally, when we perform the analysis on a
dataset, the data needs to be in order. To do this we
sort the dataset. Python actually has a built in function
called sort() that will put the data in a list in order
(ascending).

4

media
media

Example:

5

Fill in the Blank

Fill in the blank to sort the list:

myList = [9, 4, 2, 7, 1, 8, 5]
______________

.
(
)

6

media

The NumPy and
SciPy Modules

A lot of what we will be doing in this lesson is based
off of the NumPy and SciPy modules. In order to find
the mean and median, we will need to import numpy.
To find the mode we will import stats from scipy.

There are other things in these modules that we
can use in the future as well.

7

media

Finding the Mean

We use the mean function from the NumPy module to
find the mean and we pass the list in as an argument.
We must either store the returned value in a variable,
or print it to avoid it being lost.

8

media
media

Example:

9

Fill in the Blank

Fill in the blank to find the average of myList:

import numpy

myList = [9, 4, 2, 7, 1, 8, 5]

avg = _____________(myList)

.

10

media

Finding the Median

In order to find the median of a list, it first needs to be
sorted. Sorting a list is easy because lists have a built
in method called sort that we can take advantage of.
However, the median method of the NumPy module
also automatically sorts the list as well.

11

media
media

Example:

12

Fill in the Blank

Fill in the blank to find the median of myList

import numpy

myList = [9, 4, 2, 7, 1, 8, 5]

med = ______________(myList)

.

13

media

Finding the Mode

The mode is the value that is repeated the most often
in the dataset. SciPy has a function that can do it for
us. Otherwise it requires a pretty complicated
algorithm to run through the entire list. The first time
that you import the SciPy module (tested in repl) it will
need a moment to install before the program runs.

We call the mode function that is attached to stats in
the SciPy module

Another way to find the mode would be to import the
statistics module. From there we could use the mode
function.

14

media
media

SciPy Mode Example:

This is the mode.

This is the number of times it
occurred.

15

media
media

Statistics Module Mode Example:

16

Fill in the Blank

Fill in the blank to find the mode of myList

import statistics as stats

myList = [9, 4, 2, 7, 1, 8, 5, 1, 6, 3, 1, 8]

mode = _________________(myList)

.

17

media

Finding the Range
of a List

The often overlooked stat when dealing with a dataset
is range which essentially is the difference between
the largest and smallest values. Once a dataset is
sorted the range is just the absolute value of the first
element subtracted from the last. We use absolute
value so that it doesn’t matter if the list is in ascending
order (default) or descending order.

18

media
media

Example

media

Lesson 27

Mean, Median, Mode, and Range

Show answer

Auto Play

Slide 1 / 18

SLIDE