Logistic回归与最小二乘概率分类算法简述与示例
来源:互联网 发布:电脑音效软件 编辑:程序博客网 时间:2024/06/06 09:43
Logistic Regression & Least Square Probability Classification
1. Logistic Regression
Likelihood function, as interpreted by wikipedia:
https://en.wikipedia.org/wiki/Likelihood_function
plays one of the key roles in statistic inference, especially methods of estimating a parameter from a set of statistics. In this article, we’ll make full use of it.
Pattern recognition works on the way that learning the posterior probability
The posterior probability can be seen as the credibility of model
In Logistic regression algorithm, we make use of linear logarithmic function to analyze the posterior probability:
Note that the denominator is a kind of regularization term. Then the Logistic regression is defined by the following optimal problem:
We can solve it by gradient descent method:
- Initialize
θ . - Pick up a training sample
(xi,yi) randomly. - Update
θ=(θ(1)T,…,θ(c)T)T along the direction of gradient ascent:whereθ(y)←θ(y)+ϵ∇yJi(θ),y=1,…,c ∇yJi(θ)=−exp(θ(y)Tϕ(xi))ϕ(xi)∑cy′=1exp(θ(y′)Tϕ(xi))+{ϕ(xi)0(y=yi)(y≠yi) - Go back to step 2,3 until we get a
θ of suitable precision.
Take the Gaussian Kernal Model as an example:
Aren’t you familiar with Gaussian Kernal Model? Refer to this article:
http://blog.csdn.net/philthinker/article/details/65628280
Here are the corresponding MATLAB codes:
n=90; c=3; y=ones(n/c,1)*(1:c); y=y(:);x=randn(n/c,c)+repmat(linspace(-3,3,c),n/c,1);x=x(:);hh=2*1^2; t0=randn(n,c);for o=1:n*1000 i=ceil(rand*n); yi=y(i); ki=exp(-(x-x(i)).^2/hh); ci=exp(ki'*t0); t=t0-0.1*(ki*ci)/(1+sum(ci)); t(:,yi)=t(:,yi)+0.1*ki; if norm(t-t0)<0.000001 break; end t0=t;endN=100; X=linspace(-5,5,N)';K=exp(-(repmat(X.^2,1,n)+repmat(x.^2',N,1)-2*X*x')/hh);figure(1); clf; hold on; axis([-5,5,-0.3,1.8]);C=exp(K*t); C=C./repmat(sum(C,2),1,c);plot(X,C(:,1),'b-');plot(X,C(:,2),'r--');plot(X,C(:,3),'g:');plot(x(y==1),-0.1*ones(n/c,1),'bo');plot(x(y==2),-0.2*ones(n/c,1),'rx');plot(x(y==3),-0.1*ones(n/c,1),'gv');legend('q(y=1|x)','q(y=2|x)','q(y=3|x)');
2. Least Square Probability Classification
In LS probability classifiers, linear parameterized model is used to express the posterior probability:
These models depends on the parameters
By the Bayesian formula,
Hence
Note that the first term and second term in the equation above stand for the mathematical expectation of
Due to the fact that
Next, we introduce the regularization term to get the following calculation rule:
Let
Therefore, it is evident that the problem above can be formulated as a convex optimization problem, and we can get the analytic solution by setting the twice order derivative to zero:
In order not to get a negative estimation of the posterior probability, we need to add a constrain on the negative outcome:
We also take Gaussian Kernal Models for example:
n=90; c=3; y=ones(n/c,1)*(1:c); y=y(:);x=randn(n/c,c)+repmat(linspace(-3,3,c),n/c,1);x=x(:);hh=2*1^2; x2=x.^2; l=0.1; N=100; X=linspace(-5,5,N)';k=exp(-(repmat(x2,1,n)+repmat(x2',n,1)-2*x*(x'))/hh);K=exp(-(repmat(X.^2,1,n)+repmat(x2',N,1)-2*X*(x'))/hh);for yy=1:c yk=(y==yy); ky=k(:,yk); ty=(ky'*ky +l*eye(sum(yk)))\(ky'*yk); Kt(:,yy)=max(0,K(:,yk)*ty);endph=Kt./repmat(sum(Kt,2),1,c);figure(1); clf; hold on; axis([-5,5,-0.3,1.8]);C=exp(K*t); C=C./repmat(sum(C,2),1,c);plot(X,C(:,1),'b-');plot(X,C(:,2),'r--');plot(X,C(:,3),'g:');plot(x(y==1),-0.1*ones(n/c,1),'bo');plot(x(y==2),-0.2*ones(n/c,1),'rx');plot(x(y==3),-0.1*ones(n/c,1),'gv');legend('q(y=1|x)','q(y=2|x)','q(y=3|x)');
3. Summary
Logistic regression is good at dealing with sample set with small size since it works in a simple way. However, when the number of samples is large to some degree, it is better to turn to the least square probability classifiers.
- Logistic回归与最小二乘概率分类算法简述与示例
- Andrew NG 机器学习听课笔记(2)——过学习与欠学习,最小二乘的概率意义、logistic回归
- Andrew NG 机器学习听课笔记(2)——过学习与欠学习,最小二乘的概率意义、logistic回归
- 回归学习算法---偏最小二乘回归、PCA降维与理论
- 概率统计与机器学习:独立同分布,极大似然估计,线性最小二乘回归
- 机器学习--岭回归与偏最小二乘
- 最小二乘回归树生成算法
- 线性回归中最小二乘的概率解释
- 分类算法:Logistic回归
- 最小二乘回归
- 最小二乘回归
- 机器学习之logistic回归与分类
- RANSAC与最小二乘算法的应用
- RANSAC与最小二乘算法的应用
- LM算法与非线性最小二乘问题
- Logistic回归与梯度上升算法
- Logistic回归与梯度上升算法
- Logistic回归与梯度上升算法
- Qt 用com组件快速导入Excel
- 九度OJ题目1069:查找学生信息
- JVM介绍
- new Boolean() 和 Boolean.valueOf() 区别
- 数据存储---五种存储方式简介
- Logistic回归与最小二乘概率分类算法简述与示例
- ——首记
- 商店选址问题(dij)(未完成)
- Storm的安装配置
- React 学习总结
- Android之关于点击多次的导致多个页面问题
- scrapy 爬取https网页时出现ssl错误
- 1618: [Usaco2008 Nov]Buying Hay 购买干草
- 进程间通信详解