1. 程式人生 > >EL之GB(GBC):利用GB對二分類問題進行建模並評估

EL之GB(GBC):利用GB對二分類問題進行建模並評估

EL之GB(GBC):利用GB對二分類問題進行建模並評估

輸出結果

T1、純GB演算法

T2、以RF為基學習器的GB演算法

 

 

 

 

設計思路

 

核心程式碼

# nEst = 2000
# depth = 3
# learnRate = 0.007
# maxFeatures = None


nEst = 2000
depth = 3
learnRate = 0.007
maxFeatures = 20

rockVMinesGBMModel = ensemble.GradientBoostingClassifier(n_estimators=nEst, max_depth=depth,
                                                         learning_rate=learnRate,
                                                         max_features=maxFeatures)

rockVMinesGBMModel.fit(xTrain, yTrain)

auc = []
aucBest = 0.0
predictions = rockVMinesGBMModel.staged_decision_function(xTest)
for p in predictions:
    aucCalc = roc_auc_score(yTest, p)
    auc.append(aucCalc)

    if aucCalc > aucBest:
        aucBest = aucCalc
        pBest = p