输出结果
设计思路
核心代码
bagFract = 1.0 #----------------------☆☆☆☆☆
nBagSamples = int(len(xTrain) * bagFract)
for iTrees in range(numTreesMax):
idxBag = []
for i in range(nBagSamples):
idxBag.append(random.choice(range(len(xTrain))))
xTrainBag = [xTrain[i] for i in idxBag]
yTrainBag = [yTrain[i] for i in idxBag]
modelList.append(DecisionTreeRegressor(max_depth=treeDepth))
modelList[-1].fit(xTrainBag, yTrainBag)
latestPrediction = modelList[-1].predict(xTest)
predList.append(list(latestPrediction))