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?
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.61The 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
EasyTwo libraries, six days. The program reads the main library's counts into books; the village branch's are in village. Print:
Busier:the branch (mainorvillage) with the higher mean, and that mean.Steadier:the branch with the lower std, and that std.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: 60Try 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Data and Plots
2NumPy Arrays
Creating ArraysShape and SizeRanges of NumbersIndexing and SlicingRecap: Temperature Grid3Array Math
Math on Whole ArraysSummary StatisticsStatistics by AxisBroadcastingBoolean MasksRecap: Exam Scores9Grouping and Cleaning
Counting ValuesGrouping DataSeveral SummariesMissing ValuesRecap: Survey ResultsPractice on your own: Online Python compiler