@@ -124,6 +124,8 @@ S = np.arange(1, n+1)
124
124
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
125
125
ax.vlines(S, 0, u.pmf(S), lw=0.2)
126
126
ax.set_xticks(S)
127
+ ax.set_xlabel('S')
128
+ ax.set_ylabel('PMF')
127
129
plt.show()
128
130
```
129
131
@@ -136,6 +138,8 @@ S = np.arange(1, n+1)
136
138
ax.step(S, u.cdf(S))
137
139
ax.vlines(S, 0, u.cdf(S), lw=0.2)
138
140
ax.set_xticks(S)
141
+ ax.set_xlabel('S')
142
+ ax.set_ylabel('CDF')
139
143
plt.show()
140
144
```
141
145
@@ -232,6 +236,8 @@ S = np.arange(1, n+1)
232
236
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
233
237
ax.vlines(S, 0, u.pmf(S), lw=0.2)
234
238
ax.set_xticks(S)
239
+ ax.set_xlabel('S')
240
+ ax.set_ylabel('PMF')
235
241
plt.show()
236
242
```
237
243
@@ -244,6 +250,8 @@ S = np.arange(1, n+1)
244
250
ax.step(S, u.cdf(S))
245
251
ax.vlines(S, 0, u.cdf(S), lw=0.2)
246
252
ax.set_xticks(S)
253
+ ax.set_xlabel('S')
254
+ ax.set_ylabel('CDF')
247
255
plt.show()
248
256
```
249
257
@@ -267,6 +275,8 @@ u_sum = np.cumsum(u.pmf(S))
267
275
ax.step(S, u_sum)
268
276
ax.vlines(S, 0, u_sum, lw=0.2)
269
277
ax.set_xticks(S)
278
+ ax.set_xlabel('S')
279
+ ax.set_ylabel('CDF')
270
280
plt.show()
271
281
```
272
282
@@ -289,21 +299,13 @@ The mean and variance are:
289
299
``` {code-cell} ipython3
290
300
λ = 2
291
301
u = scipy.stats.poisson(λ)
292
- ```
293
-
294
- ``` {code-cell} ipython3
295
302
u.mean(), u.var()
296
303
```
297
-
298
- The the expectation of Poisson distribution is $\lambda$ and the variance is also $\lambda$.
304
+
305
+ The expectation of the Poisson distribution is $\lambda$ and the variance is also $\lambda$.
299
306
300
307
Here's the PMF:
301
308
302
- ``` {code-cell} ipython3
303
- λ = 2
304
- u = scipy.stats.poisson(λ)
305
- ```
306
-
307
309
``` {code-cell} ipython3
308
310
u.pmf(1)
309
311
```
@@ -314,6 +316,8 @@ S = np.arange(1, n+1)
314
316
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
315
317
ax.vlines(S, 0, u.pmf(S), lw=0.2)
316
318
ax.set_xticks(S)
319
+ ax.set_xlabel('S')
320
+ ax.set_ylabel('PMF')
317
321
plt.show()
318
322
```
319
323
@@ -386,7 +390,8 @@ for μ, σ in zip(μ_vals, σ_vals):
386
390
ax.plot(x_grid, u.pdf(x_grid),
387
391
alpha=0.5, lw=2,
388
392
label=f'$\mu={μ}, \sigma={σ}$')
389
-
393
+ ax.set_xlabel('x')
394
+ ax.set_ylabel('PDF')
390
395
plt.legend()
391
396
plt.show()
392
397
```
@@ -402,6 +407,8 @@ for μ, σ in zip(μ_vals, σ_vals):
402
407
alpha=0.5, lw=2,
403
408
label=f'$\mu={μ}, \sigma={σ}$')
404
409
ax.set_ylim(0, 1)
410
+ ax.set_xlabel('x')
411
+ ax.set_ylabel('CDF')
405
412
plt.legend()
406
413
plt.show()
407
414
```
@@ -446,7 +453,8 @@ for μ, σ in zip(μ_vals, σ_vals):
446
453
ax.plot(x_grid, u.pdf(x_grid),
447
454
alpha=0.5, lw=2,
448
455
label=f'$\mu={μ}, \sigma={σ}$')
449
-
456
+ ax.set_xlabel('x')
457
+ ax.set_ylabel('PDF')
450
458
plt.legend()
451
459
plt.show()
452
460
```
@@ -461,6 +469,8 @@ for σ in σ_vals:
461
469
label=f'$\mu={μ}, \sigma={σ}$')
462
470
ax.set_ylim(0, 1)
463
471
ax.set_xlim(0, 3)
472
+ ax.set_xlabel('x')
473
+ ax.set_ylabel('CDF')
464
474
plt.legend()
465
475
plt.show()
466
476
```
@@ -500,6 +510,8 @@ for λ in λ_vals:
500
510
ax.plot(x_grid, u.pdf(x_grid),
501
511
alpha=0.5, lw=2,
502
512
label=f'$\lambda={λ}$')
513
+ ax.set_xlabel('x')
514
+ ax.set_ylabel('PDF')
503
515
plt.legend()
504
516
plt.show()
505
517
```
@@ -512,6 +524,8 @@ for λ in λ_vals:
512
524
alpha=0.5, lw=2,
513
525
label=f'$\lambda={λ}$')
514
526
ax.set_ylim(0, 1)
527
+ ax.set_xlabel('x')
528
+ ax.set_ylabel('CDF')
515
529
plt.legend()
516
530
plt.show()
517
531
```
@@ -557,6 +571,8 @@ for α, β in zip(α_vals, β_vals):
557
571
ax.plot(x_grid, u.pdf(x_grid),
558
572
alpha=0.5, lw=2,
559
573
label=fr'$\alpha={α}, \beta={β}$')
574
+ ax.set_xlabel('x')
575
+ ax.set_ylabel('PDF')
560
576
plt.legend()
561
577
plt.show()
562
578
```
@@ -569,6 +585,8 @@ for α, β in zip(α_vals, β_vals):
569
585
alpha=0.5, lw=2,
570
586
label=fr'$\alpha={α}, \beta={β}$')
571
587
ax.set_ylim(0, 1)
588
+ ax.set_xlabel('x')
589
+ ax.set_ylabel('CDF')
572
590
plt.legend()
573
591
plt.show()
574
592
```
@@ -614,6 +632,8 @@ for α, β in zip(α_vals, β_vals):
614
632
ax.plot(x_grid, u.pdf(x_grid),
615
633
alpha=0.5, lw=2,
616
634
label=fr'$\alpha={α}, \beta={β}$')
635
+ ax.set_xlabel('x')
636
+ ax.set_ylabel('PDF')
617
637
plt.legend()
618
638
plt.show()
619
639
```
@@ -626,6 +646,8 @@ for α, β in zip(α_vals, β_vals):
626
646
alpha=0.5, lw=2,
627
647
label=fr'$\alpha={α}, \beta={β}$')
628
648
ax.set_ylim(0, 1)
649
+ ax.set_xlabel('x')
650
+ ax.set_ylabel('CDF')
629
651
plt.legend()
630
652
plt.show()
631
653
```
@@ -720,6 +742,8 @@ We can histogram the income distribution we just constructed as follows
720
742
x = df['income']
721
743
fig, ax = plt.subplots()
722
744
ax.hist(x, bins=5, density=True, histtype='bar')
745
+ ax.set_xlabel('income')
746
+ ax.set_ylabel('density')
723
747
plt.show()
724
748
```
725
749
@@ -760,6 +784,8 @@ x_amazon = np.asarray(data)
760
784
``` {code-cell} ipython3
761
785
fig, ax = plt.subplots()
762
786
ax.hist(x_amazon, bins=20)
787
+ ax.set_xlabel('monthly return (percent change)')
788
+ ax.set_ylabel('density')
763
789
plt.show()
764
790
```
765
791
@@ -774,6 +800,8 @@ KDE will generate a smooth curve that approximates the PDF.
774
800
``` {code-cell} ipython3
775
801
fig, ax = plt.subplots()
776
802
sns.kdeplot(x_amazon, ax=ax)
803
+ ax.set_xlabel('monthly return (percent change)')
804
+ ax.set_ylabel('KDE')
777
805
plt.show()
778
806
```
779
807
@@ -784,6 +812,8 @@ fig, ax = plt.subplots()
784
812
sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.1, alpha=0.5, label="bw=0.1")
785
813
sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.5, alpha=0.5, label="bw=0.5")
786
814
sns.kdeplot(x_amazon, ax=ax, bw_adjust=1, alpha=0.5, label="bw=1")
815
+ ax.set_xlabel('monthly return (percent change)')
816
+ ax.set_ylabel('KDE')
787
817
plt.legend()
788
818
plt.show()
789
819
```
@@ -802,6 +832,8 @@ Yet another way to display an observed distribution is via a violin plot.
802
832
``` {code-cell} ipython3
803
833
fig, ax = plt.subplots()
804
834
ax.violinplot(x_amazon)
835
+ ax.set_ylabel('monthly return (percent change)')
836
+ ax.set_xlabel('KDE')
805
837
plt.show()
806
838
```
807
839
@@ -822,6 +854,8 @@ x_apple = np.asarray(data)
822
854
``` {code-cell} ipython3
823
855
fig, ax = plt.subplots()
824
856
ax.violinplot([x_amazon, x_apple])
857
+ ax.set_ylabel('monthly return (percent change)')
858
+ ax.set_xlabel('KDE')
825
859
plt.show()
826
860
```
827
861
@@ -855,6 +889,8 @@ x_grid = np.linspace(-50, 65, 200)
855
889
fig, ax = plt.subplots()
856
890
ax.plot(x_grid, u.pdf(x_grid))
857
891
ax.hist(x_amazon, density=True, bins=40)
892
+ ax.set_xlabel('monthly return (percent change)')
893
+ ax.set_ylabel('density')
858
894
plt.show()
859
895
```
860
896
@@ -882,6 +918,8 @@ x_grid = np.linspace(-4, 4, 200)
882
918
fig, ax = plt.subplots()
883
919
ax.plot(x_grid, u.pdf(x_grid))
884
920
ax.hist(x_draws, density=True, bins=40)
921
+ ax.set_xlabel('x')
922
+ ax.set_ylabel('density')
885
923
plt.show()
886
924
```
887
925
0 commit comments