找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1551|回复: 0
打印 上一主题 下一主题
收起左侧

逻辑回归算法 Python源程序

[复制链接]
跳转到指定楼层
楼主
ID:780408 发表于 2020-12-18 11:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Python源程序如下:
  1. import pandas as pd
  2. import numpy as np
  3. test = pd.read_table('horseColicTest.txt',header=None)
  4. train = pd.read_table('horseColicTraining.txt',header=None)
  5. train.head()
  6. train.shape
  7. train.info()
  8. print(train.head())
  9. # print(test)
  10. # print(train)
  11. #
  12. # def sigmoid(inX):
  13. #     s = 1/(1+np.exp(-inX))
  14. #     return s
  15. # def classify(inX,weight):
  16. #     p = sigmoid(sum(inX*weight))
  17. #     if p <0.5:
  18. #         return 0
  19. #     else:
  20. #         return 1
  21. # def regularize(xMat):
  22. #     inMat = xMat.copy()
  23. #     inMeans = np.mean(inMat,axis = 0)
  24. #     inVar = np.std(inMat,axis = 0)
  25. #     inMat = (inMat-inMeans)/inVar
  26. #     return inMat
  27. # def SGD_LR(dataSet,alpha=0.001,maxCycles=500):
  28. #     dataSet = dataSet.sample(maxCycles,replace=True)
  29. #     dataSet.index = range(dataSet.shape[0])
  30. #     xMat = np.mat(dataSet.iloc[:,:-1].values)
  31. #     yMat = np.mat(dataSet.iloc[:,-1].values).T
  32. #     xMat = regularize(xMat)
  33. #     m,n = xMat.shape
  34. #     weights = np.zeros((n,1))
  35. #     for i in range(m):
  36. #         grad = xMat[i].T*(xMat[i]*weights-yMat[i])
  37. #         weights = weights-alpha*grad
  38. #     return weights
  39. #
  40. # def get_acc(train,test,alpha=0.001,maxCycles=5000):
  41. #     weights = SGD_LR(train,alpha,maxCycles=maxCycles)
  42. #     xMat = np.mat(test.iloc[:,:-1].values)
  43. #     xMat = regularize(xMat)
  44. #     result = []
  45. #     for inX in xMat:
  46. #         label = classify(inX,weights)
  47. #         result = []
  48. #         for inX in xMat:
  49. #             label = classify(inX,weights)
  50. #             result.append(label)
  51. #         retest = test.copy()
  52. #         retest['predict']=result
  53. #         acc= (retest.iloc[:,-1]==retest.iloc[:,-2]).mean()
  54. #         print(f'模型准确率为:{acc}')
  55. #         return retest
  56. # print(get_acc(train,test,alpha=0.001,maxCycles=5000))
  57. #
复制代码
全部资料51hei下载地址:
逻辑回归算法.zip (15.02 KB, 下载次数: 12)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表