# -- coding utf-8 --Created on Sat May 6 113130 2023author Lenovo# 导入库import numpy as np# 共 100 个样本每个样本 x 都包括 5 个特征nprandomseed0x = nprandomrandn100 5# 共 100 个样本每个样本 x 都属于 0129 类别中的一个nprandomseed0y =
初始化先验概率,P[i] 表示类别 i 出现的概率
P = np.zeros(10)
任务1:计算每个标签的先验概率
########## Begin ########## for i in range(10): P[i] = np.count_nonzero(y==i)/100 ########## End ##########
打印结果
for i in range(10): print("类别", i, "出现的概率为:", P[i])
原文地址: http://www.cveoy.top/t/topic/enq8 著作权归作者所有。请勿转载和采集!