Menu
CoddyTech

Summary Statistics

Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 11 of 60.

Two bus stops, five waits each. Both average 5 minutes. Which stop would you rather wait at?

Five waits at each of two bus stops as dots. Elm St waits spread from 2 to 9 minutes, Oak Ave waits huddle between 4 and 6, both around a mean of 5

One method each sums up an array, no loop:

elm = np.array([4, 7, 2, 9, 3])
print(elm.sum(), elm.mean(), elm.min(), elm.max())
print(np.round(elm.std(), 2))

This prints:

25 5.0 2 9
2.61

The standard deviation, .std(), is the typical distance from the mean. Oak Ave's is 0.63: buses you can count on.

np.round(x, 2) keeps 2 decimals, of one number or a whole array. Typical value, range, spread: your first look at any feature.

challenge icon

Challenge

Easy

Two libraries, six days. The program reads the main library's counts into books; the village branch's are in village. Print:

  1. Busier: the branch (main or village) with the higher mean, and that mean.
  2. Steadier: the branch with the lower std, and that std.
  3. Best single day: the largest count of either.

Round with np.round(x, 2). For main counts of 55, 58, 53, 60, 57, 56:

Busier: main, 56.5 books a day
Steadier: main, std 2.22
Best single day: 60

Try it yourself

import numpy as np

# Books borrowed at the main library on six days
counts = []
for i in range(6):
    counts.append(int(input()))
books = np.array(counts)
# Books borrowed at the village branch on the same six days
village = np.array([28, 35, 30, 33, 52, 32])

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Plots

Practice on your own: Online Python compiler