Logistic回归python代码
来源:互联网 发布:数组 reverse 编辑:程序博客网 时间:2024/04/30 00:18
参考文献:http://blog.csdn.net/dongtingzhizi/article/details/15962797
将逻辑回归的cost函数向量化
给出了线性回归的cost函数为:
对上式对每个theta求偏导:
将没给theta求得的偏导向量化:
其中,最后一步将求和去掉的原理如下:
__author__ = 'Chen'from numpy import *#calculate the costdef costFunction(X,Y,theta): mse = ( 1/(1+exp(-theta*X.T)) - Y.T) return mse *mse.T#linearReresiondef linearRegresion(x,y,alpha=0.01): xrow = shape(x)[0] xcol = shape(x)[1] x = matrix(x) Y = matrix(y) # fill ones xone = ones((xrow,1)) X = hstack((xone,x)) X = matrix(X) # gradiant theta = matrix(random.random(xcol+1)) # iterations for iteration in range(1,10000): # return the cost print costFunction(X,Y,theta),theta sums = 0 #begin gradient method error = ( 1.0/(1+exp(-X*theta.T)) - Y) test = X.T * error theta -= alpha * test.T #end gradient method return thetax= [[0.1,0.2],[0.3,0.2],[1,1],[0.9,0.8]]y= [[0],[0],[1],[1]]#gradient descenttheta2 = linearRegresion(x,y)print theta2
0 0
- Logistic回归python代码
- 【Logistic回归】原理及Python代码示例
- Logistic回归简介及python代码实现
- logistic 回归Matlab代码
- 代码笔记--Logistic回归
- Logistic回归 Python实现
- Python Logistic 回归分类
- 机器学习/逻辑回归(logistic regression)/--附python代码
- Logistic Regression 逻辑回归算法例子,python代码实现
- logistic回归算法详细分析与Python代码实现注释
- c++实现logistic回归代码
- 用Python做Logistic回归
- logistic回归与python实现
- Python实现Logistic 回归实例
- logistic回归和Python实现
- Logistic回归(Python实现)
- Logistic回归模型(C++代码实现)
- 【机器学习系列】logistic回归python实现
- SwipeRefreshLayout使用心得
- iOS UIFont 字体大全
- WARN [http-8080-1] - No mapping found for HTTP request with URI [/MyLibrary/books/listBooks.action]
- hdu2533_N皇后问题
- 语义元素
- Logistic回归python代码
- 原生javascript技巧篇
- nodejs、npm、express安装
- 支付宝免签约 免手续费 支付接口API
- C/C++求职宝典21个重点笔记(常考笔试面试点)
- 20个实用的webApp前端开发技巧
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSourc
- 常用的ie6,ie7,ie8 css bug兼容性解决
- 写在前面的话