2、Logistic Regression求解classification问题 c代码

#include "stdio.h"
#include "math.h"


   double x[6][4]={{1.0,47.0,76.0,24.0}, //include x0=1
              {1.0,46.0,77.0,23.0},
              {1.0,48.0,74.0,22.0},
              {1.0,34.0,76.0,21.0},
              {1.0,35.0,75.0,24.0},
              {1.0,34.0,77.0,25.0},
                };


double y[]={1.0,1.0,1.0,0.0,0.0,0.0};
double theta[]={1.0,1.0,1.0,1.0}; // include theta0
int i,j,k;
double ez,gz,gh;


double fun_g(double z){//重点是定义函数g(z),之后可以调用
   ez= pow(2.718,z);
   gz=ez/(1+ez);
   return gz;
}
int main(){
double fun_g(double z);
for(i=1;i<1000;i++){
   for(j=0;j<6;j++){
       double h=0.0;
      for(k=0;k<4;k++){//记住j,k都从0开始
      h=h+theta[k]*x[j][k];
      }
      gh=fun_g(h) ;
      double error=0.0;
      error=y[j]-gh;
      for(k=0;k<4;k++){
          theta[k]=theta[k]+0.01*error*x[j][k];
      }
      printf("%lf %lf %lf %lf\t",theta[0],theta[1],theta[2],theta[3]);
   }
}

}


logistics回归和线性回归的参数迭代学习规则形式完全一样,但意义不同,logistics本质上是梯度上升,logistics回归是凹函数,找局部最大值,一定是全局最大值


logistics回归用来处理分类问题,处理离散数据



http://blog.csdn.net/pennyliang/article/details/7045372

【这是别人Logistic Regression求解classification问题 的代码



Given Summed Input:

x = 

Instead of threshold, and fire/not fire,
we could have continuous output y according to the sigmoid function:设定了一个sigmoid函数

Note e and its properties
As x goes to minus infinity, y goes to 0 (tends not to fire). 
As x goes to infinity, y goes to 1 (tends to fire): 
At x=0, y=1/2


 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值