sllynn / spark-xgboost

A Python wrapper for XGBoost4J-Spark classes.
https://xgboost.readthedocs.io/en/latest/jvm/xgboost4j_spark_tutorial.html
Other
47 stars 13 forks source link

setParams() got an unexpected keyword argument 'lambda' #13

Open WL1988 opened 2 years ago

WL1988 commented 2 years ago

When I try to involve the L2 regularization parameter into the xgboostregressor by specifying the lambda_ parameter, an error occurred indicating that "TypeError: setParams() got an unexpected keyword argument 'lambda'". Could you help me to fix it? Your kind help is greatly appreciated.

sllynn commented 2 years ago

Try with a trailing underscore, i.e. lambda_. I think this was renamed to avoid the clash with python's lambda reserved keyword.

WL1988 commented 2 years ago

Try with a trailing underscore, i.e. lambda_. I think this was renamed to avoid the clash with python's lambda reserved keyword.

@sllynn Thank you very much for the advice. Actually, that's what I did to use 'lambda', i.e., the parameter I used are "model = XGBoostRegressor(objective='reg:squarederror', numRound=100, eta=0.1, maxDepth=5, alpha=0.0, lambda=1.0)", and then the aforementioned TypeError raised. I guess it is related to the code in the 'init' function of the class 'XGBoostRegressor' in below: if "lambda" in kwargs: kwargs["lambda"] = kwargs.pop("lambda") self.setParams(**kwargs)" In addition, I found that the parameter used for the L2 regularization in xgboost4jspark is 'lambda' (ref: https://xgboost.readthedocs.io/en/latest/jvm/scaladocs/xgboost4j-spark/ml/dmlc/xgboost4j/scala/spark/XGBoostRegressor.html). The rename process of replacing 'lambda' with 'lambda' is probably to ensure the parameter consistence with the scala code. Nevertheless, I don't know what I could do to fix it. Do you have any opinions on this? Thank you very much and look forward to your reply.