Created
May 19, 2021 09:20
-
-
Save 18182324/f2547cafd6cc104e1bb120629fc8f4be to your computer and use it in GitHub Desktop.
dl prob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: #If running in colab | |
import google.colab | |
IN_COLAB = True | |
%tensorflow_version 2.x | |
except: | |
IN_COLAB = False | |
import tensorflow as tf | |
if (not tf.__version__.startswith('2')): #Checking if tf 2.0 is installed | |
print('Please install tensorflow 2.0 to run this notebook') | |
print('Tensorflow version: ',tf.__version__, ' running in colab?: ', IN_COLAB) | |
#load required libraries: | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
plt.style.use('default') | |
# Assume a die with only one face with a dollar sign | |
# Calculate the probability to observe in 10 throws 1- or 2-times the $-sign | |
# See book section 4.1 | |
10*(1/6)*(5/6)**9, 45*(1/6)**2*(5/6)**8 | |
from scipy.stats import binom | |
# Define the numbers of possible successes (0 to 10) | |
ndollar = np.asarray(np.linspace(0,10,11), dtype='int') | |
# Calculate the probability to get the different number of possible successes | |
pdollar_sign = binom.pmf(k=ndollar, n=10, p=1/6) #B | |
plt.stem(ndollar, pdollar_sign) | |
plt.xlabel('Number of dollar signs') | |
plt.ylabel('Probability') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment