EL之Bagging(DTR):利用Bagging對迴歸問題(實數值評分預測)建模(調2參)
阿新 • • 發佈:2019-01-10
EL之Bagging(DTR):利用Bagging對迴歸問題(實數值評分預測)建模(調2參)
輸出結果
設計思路
核心程式碼
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))