Box–Muller变换最初由 George E. P. Box 与 Mervin E. Muller 在1958年提出
George E. P. Box 是统计学的一代大师,统计学中的很多名词术语都以他的名字命名
统计学中的名言 “All models are wrong, but some are useful”(所有模型都是错的,但其中一些是有用的)出自 Box 之口
程序检验
import random
import numpy
as np
import matplotlib
.pyplot
as plt
%matplotlib inline
import seaborn
as sns
u1
= np
.random
.random
(10000)
u2
= np
.random
.random
(10000)
z1
= np
.sqrt
(-2*np
.log
(u1
))*np
.cos
(2*np
.pi
*u2
)
z2
= np
.sqrt
(-2*np
.log
(u1
))*np
.sin
(2*np
.pi
*u2
)
核密度估计
sns
.distplot
(
z1
,
bins
= 100,
hist
= True,
kde
= True,
norm_hist
= False,
rug
= True,
vertical
= False,
color
= 'b',
label
= 'distplot',
axlabel
= 'x'
)
plt
.legend
()
正态检验
import scipy
.stats
scipy
.stats
.normaltest
(z1
)
"""
NormaltestResult(statistic=0.6940204433592375, pvalue=0.7067981035570555)
"""
两变量独立
import pandas
as pd
df
= pd
.DataFrame
({'A':z1
, 'B':z2
})
sns
.kdeplot
(df
['A'],df
['B'],
cbar
= True,
shade
= True,
cmap
= 'Reds',
shade_lowest
= False,
n_levels
= 10
)
plt
.scatter
(df
['A'],df
['B'],s
= 5, alpha
= 0.5, color
= 'k')
sns
.rugplot
(df
['A'], color
= 'g', axis
= 'x', alpha
= 0.5)
sns
.rugplot
(df
['B'], color
= 'r', axis
= 'y', alpha
= 0.5)