EL之Bagging(DTR):利用DIY数据集(预留30%数据+两种树深)训练Bagging算法(DTR)

EL之Bagging(DTR):利用DIY数据集(预留30%数据+两种树深)训练Bagging算法(DTR)


输出结果

1、treeDepth=1

2、treeDepth=5

设计思路

核心代码

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))
(0)

相关推荐