码迷,mamicode.com
首页 > 编程语言 > 详细

[转]逻辑斯蒂回归 via python

时间:2015-12-05 17:30:34      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

# -*- coding:UTF-8 -*-
import numpy
def loadDataSet():

return dataMat,labelMat

def sigmoid(inX):
return 1.0/(1+numpy.exp(-inX))

def gradAscent(dataMatIn,classLabels):
dataMatrix=numpy.mat(damaMatIn)
labelMat=numpy.mat(classLabels).transpose()
#上升梯度
alpha=0.01
#迭代次数
maxCycles=500
#初始回归向量
m,n=numpy.shape(dataMatrix)
weights=numpy.ones((n,1))

for k in range(maxCycles):
h=sigmoid(dataMatrix*weights)
error=(labelMat-h)
weights=weights+alpha*dataMatrix.transpose()*error
pass

return weights
def test():
dataArr,labelMat=loadDataSet()
print gradAscent(dataArr,labelMat)

if __name__ == ‘__main__‘:
test()

[转]逻辑斯蒂回归 via python

标签:

原文地址:http://www.cnblogs.com/lyqatdl/p/5021698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!