先明确一些潜规则:html
机器学习大概分为三个领域:网络
如此定义,有助于菜鸡入门,不用纠结严谨性。app
如何理解“通常的机器学习模型”和“统计机器学习模型”?框架
大部分人都不具有坚实的统计数学基础, such as《统计推断》,《贝叶斯分析》,但好东西仍然值得推广,那就先普及比较好理解的。dom
而所谓“通常的机器学习”,常以《机器学习导论》的姿态出现,见下图左。至于神经网络,首先,深度学习就是”更深“的神经网络,不要纠结这个梗,至于书,就是这典型的花书,见下图右。中间的prml,就是一本典型的贝叶斯机器学习书籍。机器学习
这些潜规则,确实会让菜鸡走火入魔,下载,打开目录,对比目录瞧上一瞧,就行了。固然,将来还会揭秘更多“潜规则”。ide
左:通常的机器学习 中:统计机器学习 右:深度学习函数
最近只是想对(我的的)统计机器学习知识体系作个梳理,写在这里。工具
还有一个常见问题,PGM是否是就是统计学习?PGM能够理解为一种符号工具for统计学习,“几何之于代数”,暂时先这么理解着。post
固然了,不具有必定的数学基础不要碰统计学习;不会统计学习,不要自称作机器学习。所学的最最基本的数学基础是:
贝叶斯分析 -
先说这么多做为前言,不要小看其价值,为何你没有成为”别人家的牛人”,每每不是智商问题,而是没有“课程表”。
深入了解一下概念:最大似然估计MLE、最大后验估计MAP及贝叶斯估计
这些概念有点区别,但对于“大数据”,其实结果相差无几,后二者都趋近于MLE。
小数据固然有必要纠结细节,固然还有一个缘由,就是风险估计时,详见:统计决策论
书归正传,一个例子:生成式模型
何为生成式模型?这是个比较形象的叫法,好比:生成式 --> 生孩子。既然能判断出各国孕妇生各类肤色孩子的几率,那么,已知一个小孩的肤色为白,也就能判断最可能的国籍是欧洲某国。
这里,生成式模型却用于了分类。生成式,体现的是一个“过程”;分类,体现的是一个“静态结果”。观看的角度不一样罢了,比如:电脑能够“写代码”,也能够是“游戏机”。
因此,不要纠结模型的名字,确实会带来理解上的误导。思考其核心功能价值,而后再放置在合适的知识体系角落。
画个几率图,看上去清晰明了,这也就是其存在的价值之一。
基本假设:
为何要考虑prior,有“原先的经验”固然要加以利用。
那么,开始估计topic生成各个单词的几率就行了,估计好了,就能够以后拿来预测新样本。
有菜鸡问,这难道就是人们常说的高大上的主题模型?别闹,你说的东西在这里,Latent Dirichlet Allocation。至于二者区别,不在此讨论,在此有提:[IR] Concept Search and LDA。
参数的先验形式:
参数的后验估计:
这叫作:解析解(analytical solution),跟解方程组似的,答案能够经过公式一步到位。对应的代码也易实现,以下。
def naive_bayes_posterior_mean(x, y, alpha=1, beta=1): """ Given an array of features `x`, an array of labels `y`, class prior Dirichlet parameter `alpha`, and common class-conditional feature expectation `beta` return a posterior mean, `pi`, of `alpha` and a posterior mean, `theta` of the `beta`. NB: this is not the same as returning the parameters of the full posterior, but it is sufficient to calculate the posterior predictive density. """ n_class = y.shape[1] n_feat = x.shape[1] # as a convenience, we allow both alpha and beta to be scalar values # which will be upcast to arrays for the common case of using priors to smooth # this is a no-op for alpha # but for beta, we must be explicit beta = np.ones(2) * beta pi_counts = np.sum(y, axis=0) + alpha pi = pi_counts/np.sum(pi_counts) theta = np.zeros((n_feat, n_class)) for cls in range(n_class): docs_in_class = (y[:, cls]==1) class_feat_count = x[docs_in_class, :].sum(axis=0) theta[:, cls] = (class_feat_count + beta[1])/(docs_in_class.sum() + beta.sum()) return pi, theta
第一篇,邀你入行,门槛低,骗你入坑。至于结果(解析解)的求解过程以及求解能力,可能才有点价值。
贝叶斯公式,就是要关注两个东西:似然函数,先验。
注意,这里的先验是个联合先验,虽然二者是iid。那为什么搞这么复杂?
由于有些分布的先验们并不是iid,好比高斯的均值与方差,二者互为影响。
这里仍“坚持”写成联合先验的形式,只是遵循“统一框架”,思惟的严谨性,菜鸡们看多了就习惯了。
最后,根据贝叶斯公式,天然得出了一个联合形式的参数的后验:
可见,两个参数各自的估计都是独立的事情,写成如此,也是为了迎合“统一框架”。
通常而言,获得联合分布,就是获得一切。积分积到看不顺眼的变量就天然获得了所需变量的边缘分布形式。
菜鸡问:为什么突然便跳出了后验分布结果?这是共轭先验的性质,故菜鸡先要打好数学基础。
参数的分布都有了,求参数的指望也就得出了最后的解析解。
写在本篇的最后,为何叫这么个系列,由于:
I think I'm Bayesian. For all my life taught parameters are fixed they don't come from distributions. Try to imagine: experiments repeat forever... such a silly notion! Propose this: New step. What should I do? Accept, reject? I feel free in these chains! I think I'm a Bayesian. How did this happen? Just yesterday I tested H0s. But I just learned Bayes' rule, and priors seem cool, have no p-value so how do I know? If I'm a Bay Bay Bay Bay... Bayesian? Am I a Bay Bay Bay Bay... Bayesian? I don't know if this makes sense but, I think I'm a Bayesian. Give me a sampler: I'll go and tune it; I'll fly to it; I'll burn it in; 'cause I love to run chains, cut strings, a couple things I can't do without Bayes! Yeah I'm on top of the world, when my samplers all converge! Used to shrink my coefficients, now I use stochastic search! My advisors be like, "Woah, what happened to you? Use a prior one more time and I'mma banish you to Duke!!" Accept it, I know you want to join my table at the Chinese restaurant. My posterior is charming, so why don't you try? We're conjugate! Don't be shy! Yeah I know, all the frequentists say, "Shame on you!" But I tell them take a random walk 'cause I know this is the start of something new! I think I'm a Bayesian! I think I'm a Bayesian. How did this happen? Just yesterday I tested H0s. But I just learned Bayes' rule, and priors seem cool, have no p-value so how do I know?