Lesson Introduction

Welcome to our lesson on Descriptive Statistics! In this lesson, we will learn how to summarize and describe important features of a data set. By the end, you'll know how to calculate measures like the mean and standard deviation, which are crucial for understanding data in machine learning and many other fields.

Descriptive statistics help us get a quick overview of large amounts of data. Imagine understanding the average test scores of students or the variability in their heights. Descriptive statistics provide the tools for this efficiently.

Mean
Standard Deviation
Median
Calculating in Python

Let's see how to calculate these in Python using the NumPy library.

Here's a code snippet to calculate the mean, standard deviation, and median for a list of data:

# Calculating Mean, Standard Deviation, and Median
import numpy as np

data = [1.2, 2.3, 3.1, 4.5, 5.7]

mean = np.mean(data)
std_dev = np.std(data)
median = np.median(data)

print("Mean:", mean)
print("Standard Deviation:", std_dev)
print("Median:", median)
Mean: 3.36
Standard Deviation: 1.589465318904442
Median: 3.1

Note that the mean here will be slightly different from 3.36 due to the computational error.

  1. Import NumPy: We start by importing the NumPy library for numerical operations.
  2. Data Set: We create a list of data points: [1.2, 2.3, 3.1, 4.5, 5.7].
  3. Calculate Mean: Using np.mean(data), NumPy calculates the average of the data points.
  4. Calculate Standard Deviation: Using np.std(data), NumPy calculates how much the data points vary from the mean.
  5. Calculate Median: Using np.median(data), NumPy finds the middle value of the data set.
  6. Print Results: We print the calculated mean, standard deviation, and median.
Lesson Summary

In this lesson, we learned about descriptive statistics, focusing on the mean and standard deviation. These are essential tools for summarizing and understanding data sets.

We also saw how to calculate these values using Python, making it easier to handle large data sets.

Now it's your turn to practice! In the next session, you'll be given data sets to calculate the mean and standard deviation. This will help you reinforce what you've learned and apply these concepts to real data. Let's get started!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal