Numpy实现NaiveBayes(朴素贝叶斯),2024我是如何拿到小米、京东、字节的offer

def _calculate_prior(self, c):

“”" Calculate the prior of class c

(samples where class == c / total number of samples)“”"

frequency = np.mean(self.y == c)

return frequency

def _classify(self, sample):

“”" Classification using Bayes Rule P(Y|X) = P(X|Y)*P(Y)/P(X),

or Posterior = Likelihood * Prior / Scaling Factor

P(Y|X) - The posterior is the probability that sample x is of class y given the

feature values of x being distributed according to distribution of y and the prior.

P(X|Y) - Likelihood of data X given class distribution Y.

Gaussian distribution (given by _calculate_likelihood)

P(Y) - Prior (given by _calculate_prior)

P(X) - Scales the posterior to make it a proper probability distribution.

This term is ignored in this implementation since it doesn’t affect

which class distribution the sample is most likely to belong to.

Classifies the sample as the class that results in the largest P(Y|X) (posterior)

“”"

posteriors = []

Go through list of classes

for i, c in enumerate(self.classes):

Initialize posterior as prior

posterior = self._calculate_prior©

Naive assumption (independence):

P(x1,x2,x3|Y) = P(x1|Y)*P(x2|Y)*P(x3|Y)

Posterior is product of prior and likelihoods (ignoring scaling factor)

for feature_value, params in zip(sample, self.parameters[i]):

Likelihood of feature value given distribution of feature values given y

likelihood = self._calculate_likelihood(params[“mean”], params[“var”], feature_value)

posterior *= likelihood

posteriors.append(posterior)

Return the class with the largest posterior probability

return self.classes[np.argmax(posteriors)]

现在能在网上找到很多很多的学习资源,有免费的也有收费的,当我拿到1套比较全的学习资源之前,我并没着急去看第1节,我而是去审视这套资源是否值得学习,有时候也会去问一些学长的意见,如果可以之后,我会对这套学习资源做1个学习计划,我的学习计划主要包括规划图和学习进度表。

分享给大家这份我薅到的免费视频资料,质量还不错,大家可以跟着学习

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Python爬虫全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:python)
img

、讲解视频**

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:python)
[外链图片转存中…(img-xNRGetlQ-1711058281271)]

  • 24
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值