Skip to content

Commit f75e8a8

Browse files
author
Hugo Bowne-Anderson
authored
PEP8ify your life, get on down.
https://www.youtube.com/watch?v=WKnr9sWivsI
1 parent d0da061 commit f75e8a8

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

notebooks/01-Instructor-Probability_a_simulated_introduction.ipynb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@
414414
],
415415
"source": [
416416
"n_samples = 10000\n",
417-
"sum(np.random.choice(lengths,n_samples, replace=True) > 10)/n_samples"
417+
"sum(np.random.choice(lengths, n_samples, replace=True) > 10)/n_samples"
418418
]
419419
},
420420
{
@@ -473,7 +473,7 @@
473473
"np.random.seed(seed=16071982)\n",
474474
"\n",
475475
"# Simulate one run of flipping the biased coin 10 times\n",
476-
"np.random.binomial(10,0.7)"
476+
"np.random.binomial(10, 0.7)"
477477
]
478478
},
479479
{
@@ -503,7 +503,7 @@
503503
],
504504
"source": [
505505
"# Simulate 1,000 run of flipping the biased coin 10 times\n",
506-
"x = np.random.binomial(10,0.3,10000)\n",
506+
"x = np.random.binomial(10, 0.3, 10000)\n",
507507
"\n",
508508
"# Plot normalized histogram of results\n",
509509
"plt.hist(x, density=True, bins=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);"
@@ -548,7 +548,7 @@
548548
],
549549
"source": [
550550
"# Solution\n",
551-
"sum(np.random.binomial(20,0.3,10000) >= 5)/10000"
551+
"sum(np.random.binomial(20, 0.3, 10000) >= 5)/10000"
552552
]
553553
},
554554
{
@@ -603,7 +603,7 @@
603603
],
604604
"source": [
605605
"# Plot histogram \n",
606-
"x = np.random.binomial(10,0.5,10000)\n",
606+
"x = np.random.binomial(10, 0.5, 10000)\n",
607607
"plt.hist(x, density=True);"
608608
]
609609
},
@@ -685,7 +685,7 @@
685685
],
686686
"source": [
687687
"# Solution: Calculate P(A,B)\n",
688-
"x_0 = np.random.binomial(2,0.5,10000)\n",
688+
"x_0 = np.random.binomial(2, 0.5, 10000)\n",
689689
"p_ab = sum(x_0==2)/len(x_0)\n",
690690
"plt.hist(x_0);\n",
691691
"print(p_ab)"
@@ -709,8 +709,8 @@
709709
],
710710
"source": [
711711
"# Solution: Calculate P(A)P(B)\n",
712-
"x_1 = np.random.binomial(1,0.5,10000)\n",
713-
"x_2 = np.random.binomial(1,0.5,10000)\n",
712+
"x_1 = np.random.binomial(1, 0.5, 10000)\n",
713+
"x_2 = np.random.binomial(1, 0.5, 10000)\n",
714714
"p_a = sum(x_1 == 1)/len(x_1)\n",
715715
"p_b = sum(x_2 == 1)/len(x_2)\n",
716716
"p_a*p_b"
@@ -789,8 +789,8 @@
789789
"source": [
790790
"# Calculate P(A)P(B) using resampling methods\n",
791791
"n_samples = 100000\n",
792-
"p_a = sum(np.random.choice(lengths,n_samples, replace=True) > 10)/n_samples\n",
793-
"p_b = sum(np.random.choice(lengths,n_samples, replace=True) > 10)/n_samples\n",
792+
"p_a = sum(np.random.choice(lengths, n_samples, replace=True) > 10)/n_samples\n",
793+
"p_b = sum(np.random.choice(lengths, n_samples, replace=True) > 10)/n_samples\n",
794794
"p_a*p_b"
795795
]
796796
},
@@ -820,8 +820,8 @@
820820
"source": [
821821
"# Calculate P(A,B) using resampling methods\n",
822822
"n_samples = 100000\n",
823-
"samples = np.random.choice(lengths,(n_samples,2), replace=True)\n",
824-
"_ = samples > (10,10)\n",
823+
"samples = np.random.choice(lengths, (n_samples,2), replace=True)\n",
824+
"_ = samples > (10, 10)\n",
825825
"p_ab = sum(np.prod(_, axis=1))/n_samples\n",
826826
"p_ab"
827827
]
@@ -983,7 +983,7 @@
983983
"# Take 10,000 subjects\n",
984984
"n = 100000\n",
985985
"# Sample for number of users, non-users\n",
986-
"users = np.random.binomial(n,0.005,1) \n",
986+
"users = np.random.binomial(n, 0.005, 1) \n",
987987
"non_users = n - users"
988988
]
989989
},
@@ -994,9 +994,9 @@
994994
"outputs": [],
995995
"source": [
996996
"# How many of these users tested +ve ?\n",
997-
"u_pos = np.random.binomial(users,0.99)\n",
997+
"u_pos = np.random.binomial(users, 0.99)\n",
998998
"# How many of these non-users tested +ve ?\n",
999-
"non_pos = np.random.binomial(non_users,0.01)"
999+
"non_pos = np.random.binomial(non_users, 0.01)"
10001000
]
10011001
},
10021002
{

notebooks/02-Instructor-Parameter_estimation_hypothesis_testing.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@
137137
" n_successes = np.random.binomial(N, p)\n",
138138
" # X-axis for PDF\n",
139139
" x = np.linspace(0, 1, 100)\n",
140-
" #prior\n",
140+
" # Prior\n",
141141
" prior = 1\n",
142+
" # Posterior\n",
142143
" posterior = x**n_successes*(1-x)**(N-n_successes)*prior\n",
143144
" posterior /= np.max(posterior) # so that peak always at 1\n",
144145
" plt.plot(x, posterior)\n",
@@ -362,7 +363,7 @@
362363
"# click-through rates\n",
363364
"p_a = 0.15\n",
364365
"N = 150\n",
365-
"n_successes_a = np.sum(np.random.binomial(N,p_a))"
366+
"n_successes_a = np.sum(np.random.binomial(N, p_a))"
366367
]
367368
},
368369
{

0 commit comments

Comments
 (0)