oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Probability Distributions #420

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

Random Variables

A random variable is, in its simplest form, a function. In probability, we often use random variables to represent random events. For example, we could use a random variable to represent the outcome of a die roll: any number between one and six.

Random variables must be numeric, meaning they always take on a number rather than a characteristic or quality. If we want to use a random variable to represent an event with non-numeric outcomes, we can choose numbers to represent those outcomes. For example, we could represent a coin flip as a random variable by assigning "heads" a value of 1 and "tails" a value of 0.

We will use random.choice(a, size = size, replace = True/False) from the numpy library to simulate random variables in python. In this method:

The following code simulates the outcome of rolling a fair die twice using np.random.choice():

oldoc63 commented 1 year ago

Run the given as is code to simulate rolling a die five times.

oldoc63 commented 1 year ago

Change the value of num_rolls so that results_1 has the results of rolling a die ten times.

oldoc63 commented 1 year ago

Using the range function, create a 12-sided die called die_12. Use similar logic as die_6.

oldoc63 commented 1 year ago

Simulate rolling die_12 ten times, and save the rolls as results_2. Use the np.random.choice() function to simulate the rolls, and be sure to print out your results.