scipy stats.cauchy() | Python
scipy.stats.cauchy()是一个柯西连续随机变量,使用标准格式和一些形状参数定义以完成其规范。
Parameters :
q : lower and upper tail probability
x : quantiles
loc : [optional]location parameter. Default = 0
scale : [optional]scale parameter. Default = 1
size : [tuple of ints, optional] shape or random variates.
moments : [optional] composed of letters [‘mvsk’]; ‘m’ = mean, ‘v’ = variance, ‘s’ = Fisher’s skew and ‘k’ = Fisher’s kurtosis. (default = ‘mv’).
Results : cauchy continuous random variable
代码#1:创建柯西连续随机变量
# importing scipy
from scipy.stats import cauchy
numargs = cauchy.numargs
[] = [0.6, ] * numargs
rv = cauchy()
print ("RV : \n", rv)
输出 :
RV :
代码#2:柯西随机变量和概率分布函数。
import numpy as np
quantile = np.arange (0.01, 1, 0.1)
import numpy as np
import matplotlib.pyplot as plt
distribution = np.linspace(0, np.minimum(rv.dist.b, 5))
print("Distribution : \n", distribution)
plot = plt.plot(distribution, rv.pdf(distribution))
输出 :
Random Variates :
[ 2.73388202 4.88389383 -4.89271415 4.63864536 -0.36933865 1.51521875
1.43853452 -0.69619917 -0.68358229 4.13179831]
Probability Distribution :
[0.31827806 0.31450438 0.30486533 0.29040223 0.27250226 0.25260685
0.23198738 0.21162814 0.19220451 0.17412061]
代码#3:图形表示。
import numpy as np
import matplotlib.pyplot as plt
distribution = np.linspace(0, np.minimum(rv.dist.b, 5))
print("Distribution : \n", distribution)
plot = plt.plot(distribution, rv.pdf(distribution))
输出 :
Distribution :
Distribution :
[0. 0.10204082 0.20408163 0.30612245 0.40816327 0.51020408
0.6122449 0.71428571 0.81632653 0.91836735 1.02040816 1.12244898
1.2244898 1.32653061 1.42857143 1.53061224 1.63265306 1.73469388
1.83673469 1.93877551 2.04081633 2.14285714 2.24489796 2.34693878
2.44897959 2.55102041 2.65306122 2.75510204 2.85714286 2.95918367
3.06122449 3.16326531 3.26530612 3.36734694 3.46938776 3.57142857
3.67346939 3.7755102 3.87755102 3.97959184 4.08163265 4.18367347
4.28571429 4.3877551 4.48979592 4.59183673 4.69387755 4.79591837
4.89795918 5. ]
代码#4:改变位置参数
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1.0, 100)
# Varying positional arguments
y1 = cauchy.pdf(x, 2.75, 2.75)
y2 = cauchy.pdf(x, 3.25, 3.25)
plt.plot(x, y1, "*", x, y2, "r--")
输出 :