You will learn:
How to describe a collection of data point as a distribution, and what some common distributions look like when plotted
How to describe a distribution using mean, variance, and standard deviation of a sequence of numbers
How to put a confidence metric around calculation of mean
Basic probability calculations and how to describe the likelihood of an event as a percentage
Random number generation in Python is a process of creating numbers that appear to be random and unpredictable, though they're actually generated through algorithms. These generators can be used in various applications like simulations, games, statistical sampling, and machine learning.
The three main ways we'll focus on for random number generation in Python are:
import random
The pure Python way of generating random numbers
Great for basic needs and straightforward randomization
import numpy as np
Perfect for scientific computing and large datasets
More powerful and faster for larger operations
import random, and import math
Combines randomization with mathematical functions
Useful when you need both random numbers and mathematical calculations in one
Here are three simple examples that are easy to understand: Run, and modify to see how they work!
1.Using the "Random" library
Let's make a basic number picker - like rolling a digital dice!
a) Run the code and record the value.
b) Adjust the values from 1 to 20, to go to 1 to 500.
c) Run the code again and record the new value.
2. Using the "Numpy" Library
Now let's create multiple random numbers all at once - rolling many dice together!
a) Run the code as is and record your output.
b) Alter the code to change the size=5 to a different number.
c) Run the new code and record your output.
3. Using the combination of "Random" + "Math" libraries
Finally, let's use math with random numbers to plot points on a circle - like spinning a digital compass
a) Run the code as-is and record the point on the circle.
b) Change the radius to a larger value.
c) Run the new code and record the new point on the circle.
Random Number generation is highly important in understanding probability and statistics. Let's check the foundational knowledge before continuing into statistical applications.
Expected Output:
Try it yourself! Fill in the code to calculate the variance and standard deviation of the given dataset.
Sometimes, manually computing statistics like the standard deviation can be tedious. Thankfully, Python provides many pre-written functions that make these calculations quick and easy. Below is a list of important functions you can use when working with distributions. Feel free to refer back to this page as a reminder throughout this module!