Code Monkey home page Code Monkey logo

dsc-1-08-16-bernoulli-and-binomial-distribution-lab's Introduction

Bernoulli and Binomial Distribution - Lab

Introduction

In this lab, you'll practice your newly gained knowledge on the Bernoulli and Binomial Distribution.

Objectives

You will be able to:

  • Apply the formulas for the Binomial and Bernoulli distribution
  • Apply NumPy to randomly generate Binomial and Bernoulli trials
  • Use Matplotlib to generate Binomial and Bernoulli trials with various probabilities

Apply the formulas for the Binomial and Bernoulli distribution

When playing a game of bowling, what is the probability of throwing exactly 3 strikes in a game with 10 rounds? Assume that the probability of throwing a strike is 25% for each round. Use the formula for the Binomial distribution to get to the answer. You've created this before, so we provide you with the function for factorials again:

def factorial(n):
    prod = 1
    while n >= 1:
        prod = prod * n
        n = n - 1
    return prod
p_3_strikes = None #answer = 0.2502822

Now, create a function for the Binomial distribution with three arguments $n$, $p$ and $k$ just like in the formula.

def binom_distr(n,p,k):
    None

Validate your previous result applying your new function.

None  

Now write a for loop along with your function to compute the probability that you have five strikes or more in one game. You'll want to use numpy here!

import numpy as np
None

Use a simulation to get the probabilities for all the potential outcomes

Repeat the experiment 5000 times.

# leave the random seed here 
np.random.seed(123)
#
#
#
#
# the results should look like this:
# [0 1 2 3 4 5 6 7 8]
# [ 310  941 1368 1286  707  297   78   11    2]

Visualize these results

Make sure to set an appropriate title and appropriate y-axis label

import matplotlib.pyplot as plt
#
#
#
#

You can see that, with a 25% strike hit rate, even when simulating 5000 times, an almost perfect and perfect game of 9 and 10 strikes didn't even occur once! If you change your seed, however, you'll see that occasionally perfect games will show up randomly.

Summary

Congratulations! In this lab, you practiced your newly gained knowledge on the Bernoulli and Binomial Distribution.

dsc-1-08-16-bernoulli-and-binomial-distribution-lab's People

Contributors

loredirick avatar peterbell avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dsc-1-08-16-bernoulli-and-binomial-distribution-lab's Issues

numpy is not working properly

numpy is not installing properly in this lab. It isn't recognizing np.array as an array and it thinks that it is a list. numpy is working fine on my computer itself and on other labs. Just not this one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.