DL之GD:利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)


岁月静好
软件大全 2022-09-19 11:51:26 50948
分类专栏: 资讯

DL之GD:利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)

目录

利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)

设计思路

输出结果

核心代码


相关文章
DL之GD:利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)
DL之GD:利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)实现

​​​​​​​

利用LogisticGD算法(梯度下降)依次基于一次函数和二次函数分布的数据集实现二分类预测(超平面可视化)

设计思路

后期更新……

输出结果

  1. [ 1. 0.06747879 -0.97085008]
  2. data_x
  3. (300, 3) [[ 1. 0.83749402 0.80142971]
  4. [ 1. -0.93315714 0.91389867]
  5. [ 1. -0.72558136 -0.43234329]
  6. [ 1. 0.21216637 0.88845027]
  7. [ 1. 0.70547108 -0.99548153]]
  8. 因为Linear_function函数无意义,经过Linear_function函数处理后,data_x等价于data_z
  9. data_y
  10. (300,) [-1. -1. -1. -1. 1.]
  11. data_x: (300, 3)
  12. data_z: (300, 3)
  13. data_y: (300,)
  14. [228 106 146 250 91 214 47 49 178 90]
  15. Number of iterations: 26
  16. Plot took 0.10 seconds.
  17. Plot took 0.04 seconds.
  18. Target weights: [ -0.49786797 5.28778784 -11.997255 ]
  19. Target in-sample error: 3.33%
  20. Target out-of-sample error: 6.21%
  21. Hypothesis (N=300) weights: [-0.45931854 3.20434478 -7.70825364]
  22. Hypothesis (N=300) in-sample error: 4.33%
  23. Hypothesis (N=300) out-of-sample error: 6.08%
  24. Hypothesis (N=10) weights: [-1.35583449 3.90067866 -5.99553537]
  25. Hypothesis (N=10) in-sample error: 10.00%
  26. Hypothesis (N=10) out-of-sample error: 12.87%
  27. Error history took 88.89 seconds.
  28. Plot took 17.72 seconds.
  29. Plot took 35.88 seconds.
  30. GD_w_hs[-1] [-1.35583449 3.90067866 -5.99553537]
  31. dimension_z 5
  32. data_x
  33. (30, 3) [[ 1. -0.0609991 -0.15447425]
  34. [ 1. -0.13429796 -0.89691689]
  35. [ 1. 0.12475253 0.36980185]
  36. [ 1. -0.0182513 0.74771272]
  37. [ 1. 0.50585605 -0.04961719]]
  38. 因为Linear_function函数无意义,经过Linear_function函数处理后,data_x等价于data_z
  39. data_y
  40. (30,) [-1. 1. 1. 1. -1.]
  41. Plot took 1.02 seconds.
  42. Number of iterations: 105
  43. Plot took 1.03 seconds.
  44. Target weights: [-3 2 3 6 9 10]
  45. Hypothesis weights: [-1.23615696 -0.9469097 1.76449666 2.09453304 5.62678124 5.06054409]
  46. Hypothesis in-sample error: 10.00%
  47. Hypothesis out-of-sample error: 15.47%
  48. Plot took 16.58 seconds.
  49. GD_w_hs[-1] [-1.23615696 -0.9469097 1.76449666 2.09453304 5.62678124 5.06054409]

核心代码

  1. def in_sample_error(z, y, logisticGD_function):
  2. y_h = (logisticGD_function(z) >= 0.5)*2-1
  3. return np.sum(y != y_h) / float(len(y))
  4. def estimate_out_of_sample_error(Product_x_function, NOrderPoly_Function,Pre_Logistic_function, logisticGD_function, N=10000, Linear_function_h=None):
  5. x = np.array([Product_x_function() for i in range(N)])
  6. z = np.apply_along_axis(NOrderPoly_Function, 1, x)
  7. if not Linear_function_h is None:
  8. z_h = np.apply_along_axis(Linear_function_h, 1, x)
  9. else:
  10. z_h = z
  11. y = Pre_Logistic_function(z)
  12. y_h = (logisticGD_function(z_h) >= 0.5)*2-1
  13. return np.sum(y != y_h) / float(N)
  14. def ErrorCurve_Plot(N,GD_w_hs, cross_entropy_error):
  15. start_time = time.time()
  16. fig = plt.figure() figsize=(8, 6)
  17. ax = fig.add_subplot(1, 1, 1)
  18. ax.set_xlabel(r'Iteration', fontsize=12)
  19. ax.set_ylabel(r'In-Sample Error ($E_{in}$)', fontsize=12)
  20. ax.set_title(r'Gradient Descent Evolution, N={}'.format(N), fontsize=12)
  21. ax.set_xlim(0, GD_w_hs.shape[0]-1)
  22. ax.set_ylim(0, 1)
  23. ax.xaxis.grid(color='gray', linestyle='dashed')
  24. ax.yaxis.grid(color='gray', linestyle='dashed')
  25. ax.set_axisbelow(True)
  26. ax.plot(range(GD_w_hs.shape[0]), np.apply_along_axis(cross_entropy_error, 1, GD_w_hs), 'r-')
  27. plt.show()
  28. print('Plot took {:.2f} seconds.'.format(time.time()-start_time))

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=2174
赞同 0
评论 0 条
软件大全L3
粉丝 0 发表 25 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2941
【软件正版化】软件正版化工作要点  2860
统信UOS试玩黑神话:悟空  2819
信刻光盘安全隔离与信息交换系统  2712
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1246
grub引导程序无法找到指定设备和分区  1213
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  163
点击报名 | 京东2025校招进校行程预告  162
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  160
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!