Page1.jpg

Page2.jpg
Page3.jpg
Page4.jpg
Page5.jpg
Page6.jpg
Page7.jpg
Page8.jpg

代码练习部分

from scipy.special import comb, perm
import numpy as np


#二项分布
def B(n, k, p):
    return comb(n, k) * p**k *(1-p)**(n-k);

#协方差
def Cov(X, Y):
    X = np.array(X)
    Y = np.array(Y)
    Ex = np.sum(X) / X.shape[0]
    Ey = np.sum(Y) / X.shape[0]
    Exy = np.sum(X * Y) / X.shape[0]
    return Exy - Ex * Ey

#相关系数
def Rho(X, Y):
    Covxy = Cov(X, Y)
    X = np.array(X)
    Y = np.array(Y)
    Ex = np.sum(X) / X.shape[0]
    Ey = np.sum(Y) / X.shape[0]
    Varx = np.sum(np.square(X - Ex))
    Vary = np.sum(np.square(Y - Ey))
    return Covxy / (np.sqrt(Varx) * np.sqrt(Vary))

#贝叶斯公式
def Bayes(Pa, Pb, P):
    return (P * Pa) / ((P * Pa) + (1 - P) * Pb)


if __name__ == '__main__':
    print(Bayes(0.7, 0.3, Bayes(0.7, 0.3, 0.5)))

标签: none

添加新评论