政策资讯

Policy Information


EL之Bagging:利用Bagging算法实现回归预测(实数值评分预测)问题

来源: 重庆市软件正版化服务中心    |    时间: 2022-09-19    |    浏览量: 69317    |   

EL之Bagging:利用Bagging算法实现回归预测(实数值评分预测)问题

目录

输出结果

设计思路

核心思路


输出结果

设计思路

核心思路

  1. 4.1、当treeDepth=1,对图进行可视化
  2. (1)、定义numTreesMax、treeDepth
  3. numTreesMax = 30
  4. treeDepth = 1 ----------------------▲▲▲▲▲
  5. modelList = []
  6. predList = []
  7. number of samples to draw for stochastic bagging
  8. nBagSamples = int(len(xTrain) * 0.5)
  9. for iTrees in range(numTreesMax):
  10. idxBag = []
  11. for i in range(nBagSamples):
  12. idxBag.append(random.choice(range(len(xTrain))))
  13. xTrainBag = [xTrain[i] for i in idxBag]
  14. yTrainBag = [yTrain[i] for i in idxBag]
  15. modelList.append(DecisionTreeRegressor(max_depth=treeDepth))
  16. modelList[-1].fit(xTrainBag, yTrainBag)
  17. latestPrediction = modelList[-1].predict(xTest)
  18. predList.append(list(latestPrediction))
  19. mse = []
  20. allPredictions = []
  21. for iModels in range(len(modelList)):
  22. prediction = []
  23. for iPred in range(len(xTest)):
  24. prediction.append(sum([predList[i][iPred] for i in range(iModels + 1)])/(iModels + 1))
  25. allPredictions.append(prediction)
  26. errors = [(yTest[i] - prediction[i]) for i in range(len(yTest))]
  27. mse.append(sum([e * e for e in errors]) / len(yTest))
  28. 4.2、当treeDepth=1,对图进行可视化
  29. (1)、定义numTreesMax、treeDepth
  30. numTreesMax = 30
  31. treeDepth = 5 ----------------------▲▲▲▲▲
  32. 4.3、当treeDepth=12,对图进行可视化
  33. (1)、定义numTreesMax、treeDepth
  34. numTreesMax = 100 ----------------------☆☆☆☆☆
  35. treeDepth = 12 ----------------------☆☆☆☆☆

评论

QQ咨询 扫一扫加入群聊,了解更多平台咨询
微信咨询 扫一扫加入群聊,了解更多平台咨询
意见反馈
立即提交
QQ咨询
微信咨询
意见反馈