>>> logRegres.multiTest()
Warning (from warnings module):
  File "E:/AI/FirstPythonProj\logRegres.py", line 13
    return 1.0/(1+exp(-inX))
RuntimeWarning: overflow encountered in exp
the error rate of this test is: 0.388060
the error rate of this test is: 0.388060
the error rate of this test is: 0.388060
the error rate of this test is: 0.388060
the error rate of this test is: 0.417910
the error rate of this test is: 0.298507
the error rate of this test is: 0.298507
the error rate of this test is: 0.358209
the error rate of this test is: 0.298507
the error rate of this test is: 0.298507

after 10 iterations the average error rate is: 0.352239

再次运行logRegres.multiTest()时,没有第一次的警告,sigmoid函数优化可避免类似问题:

def sigmoid(inX):
    from numpy import exp
    return 1.0/(1+exp(-inX))
def sigmoid(inX):
    from numpy import exp
    #return 1.0/(1+exp(-inX))
    #优化20180412
    if inX>=0:
        return 1.0/(1+exp(-inX))
    else:
        return exp(inX)/(1+exp(inX))


Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐