XGBoost Best Iteration

前端 未结 2 765
别跟我提以往
别跟我提以往 2021-01-18 13:21

I am running a regression using the XGBoost Algorithm as,

clf = XGBRegressor(eval_set = [(X_train, y_train), (X_val, y_val)],
                       early_st         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 13:59

    Your error is that the booster attribute of XGBRegressor is a string that specifies the kind of booster to use, not the actual booster instance. From the docs:

    booster: string
    Specify which booster to use: gbtree, gblinear or dart.

    In order to get the actual booster, you can call get_booster() instead:

    >>> clf.booster
    'gbtree'
    >>> clf.get_booster()
    
    >>> clf.get_booster().best_iteration
    9
    >>> print("Best Iteration: {}".format(clf.get_booster().best_iteration))
    Best Iteration: 9
    

    I'm not sure about the second half of your question, namely:

    Furthermore, how can I print the training error of ** each round**?

    but hopefully you're unblocked!

提交回复
热议问题