天天看點

EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)

輸出結果

EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)
EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)
EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)
EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)

設計思路

EL之Boosting之GB(DTR):簡單回歸問題使用梯度提升法(DIY資料集+DTR模型+調兩參)

核心代碼

for iTrees in range(numTreesMax):

   modelList.append(DecisionTreeRegressor(max_depth=treeDepth))

   modelList[-1].fit(xTrain, residuals)

   latestInSamplePrediction = modelList[-1].predict(xTrain)

   residuals = [residuals[i] - eps * latestInSamplePrediction[i] for i in range(len(residuals))]

   latestOutSamplePrediction = modelList[-1].predict(xTest)

   predList.append(list(latestOutSamplePrediction))

mse = []

allPredictions = []

for iModels in range(len(modelList)):

   prediction = []

   for iPred in range(len(xTest)):

       prediction.append(sum([predList[i][iPred] for i in range(iModels + 1)]) * eps)

   allPredictions.append(prediction)

   errors = [(yTest[i] - prediction[i]) for i in range(len(yTest))]

   mse.append(sum([e * e for e in errors]) / len(yTest))

繼續閱讀