第五篇[机器学习] 机器学习,逻辑回归come on

 

 

逻辑回归,简单的说,就是用sigmoid函数把连续函数归一化转化成离散的几个可能的结果。

逻辑回归的算法

最大似然法: 我自己的理解,最大似然法就是在你观测到某一系列事件出现的可能性之后,倒推该事件最可能的概率,这个最可能的概率会使这一系列事件发生的可能性无限接近我们观测到的可能性。

 

 梯度下降法

 推荐看这些文章:

http://www.jianshu.com/p/1121509ac1dc

http://blog.csdn.net/zouxy09/article/details/8537620

http://blog.csdn.net/hjl240/article/details/52402912

http://blog.csdn.net/pakko/article/details/37878837

 在实际使用的时候,可以直接调用sklearn里面的LogisticRegression

 

from sklearn import cross_validation
from sklearn.linear_model import LogisticRegression  #逻辑回归
#Initialize our algorithm
alg=LogisticRegression(random_state=1)
#Compute the accuracy score for all the cross validation folds.(much simpler than what we did before!)
scores = cross_validation.cross_val_score(alg,titanic[predictors],titanic["Survived"],cv=3)
#Take the mean of the scores (because we have one for each fold)
print(scores.mean())

 概率明显提升。

 

看一下其他数据的使用。

 参考:http://blog.csdn.net/han_xiaoyang/article/details/49123419

为了防止像直线回归那样有过拟合的情况存在,可以在逻辑回归代价函数后面加上系数的惩罚项。

最后总结:并不想总当搬运工,但是感觉人家都写的好好的,能让人看懂就好,以后慢慢自己再写一份,羞愧的低下了我的头。

 

posted @ 2017-09-09 23:37  TimoTong  阅读(215)  评论(0编辑  收藏  举报