WestCoastProjects
WestCoastProjects

Reputation: 63192

How to set the lambda parameter for xgboost

I have an interesting little issue: there is a lambda regularization parameter to xgboost. Well.. they call it .. lambda .. which presents a problem when attempting to actually use that parameter:

models["xgboost"] = XGBRegressor(lambda=Lambda,n_estimators=NTrees 
   learning_rate=LearningRate, max_depth=MaxDepth, 
   max_features=MaxFeatures,rate_drop=0, loss="huber",eta=Eta, 
   gamma=Gamma,subsample=Subsample,colsample_bytree=Colsample_bytree,
                                  eval_metric=eval_metric)

Well.. lambda is as we know a python keyword. So we have not made the compiler .. pleased ..

    lambda=Lambda)
          ^
SyntaxError: invalid syntax

I looked into whether python supports escaping variable names. afaict it is not supported. So .. how to set this parameter (short of using positional ..)

Upvotes: 5

Views: 6787

Answers (1)

Chris
Chris

Reputation: 1668

The XGBRegressor parameter you are looking for is reg_lambda, as you are using xgboost's scikit-learn API.

You may then wonder why xgb has a parameter called lambda, which works without issue. The reason is because the variable scope is local to the train method.

Upvotes: 7

Related Questions