# 导入库import numpy as np# 共 100 个样本每个样本 x 都包括 5 个特征nprandomseed0x = nprandomrandint02100 5# 共 100 个样本每个样本 x 都属于 01 类别中的一个nprandomseed0y = nprandomrandint02100# 给定 xx = 01011xx = nparray01011setx = # se
任务1:根据条件独立假设,求样本 xx 属于 i 类别的概率
for i in range(2): for j in range(5): p[i] *= np.sum(setx[i][:,j] == xx[j]) / setx[i].shape[0]
任务2:根据离散型朴素贝叶斯判定准则,求样本 xx 属于哪个类别的概率最大
label = np.argmax(p)
原文地址: https://www.cveoy.top/t/topic/enDw 著作权归作者所有。请勿转载和采集!