Menu
CoddyTech

Recap: Battery Life

Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 12 of 64.

challenge icon

Challenge

Easy

Draw the chart this chapter opened with. hours holds 300 laptop battery lives. Using their mean and std (np.std):

  1. Print the shortest life and how many std below the mean it lies (2 decimals).
  2. Print the percent within 2 std (1 decimal).
  3. Draw a density histogram (bins=20), the fitted curve (100 points) and a red dot under the worst battery, at height 0.
  4. Title Battery Life, axes Hours and Density.

For another test of 250 laptops:

Worst battery: 9.7 hours, 2.94 std below the mean
Within 2 std: 95.2% (the rule says about 95%)

and the chart:

A density histogram titled Battery Life, from about 10 to 18 hours, with a bell curve over it and a red dot at height 0 under the shortest battery life

Try it yourself

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

# Don't change the lines below
rng = np.random.default_rng(44)
hours = np.round(rng.normal(14, 1.5, size=300), 1)

# Write your code below

All lessons in Statistics for ML

Practice on your own: Online Python compiler