@@ -412,6 +412,7 @@ def lgbm_regression_learner(df: pd.DataFrame,
412
412
learning_rate : float = 0.1 ,
413
413
num_estimators : int = 100 ,
414
414
extra_params : Dict [str , Any ] = None ,
415
+ categorical_features : Union [List [str ], str ] = "auto" ,
415
416
prediction_column : str = "prediction" ,
416
417
weight_column : str = None ,
417
418
encode_extra_cols : bool = True ) -> LearnerReturnType :
@@ -458,6 +459,11 @@ def lgbm_regression_learner(df: pd.DataFrame,
458
459
https://github.com/Microsoft/LightGBM/blob/master/docs/Parameters.rst
459
460
If not passed, the default will be used.
460
461
462
+ categorical_features : list of str, or 'auto', optional (default="auto")
463
+ A list of column names that should be treated as categorical features.
464
+ See the categorical_feature hyper-parameter in:
465
+ https://github.com/Microsoft/LightGBM/blob/master/docs/Parameters.rst
466
+
461
467
prediction_column : str
462
468
The name of the column with the predictions from the model.
463
469
@@ -474,17 +480,17 @@ def lgbm_regression_learner(df: pd.DataFrame,
474
480
params = assoc (params , "eta" , learning_rate )
475
481
params = params if "objective" in params else assoc (params , "objective" , 'regression' )
476
482
477
- weights = df [weight_column ]. values if weight_column else None
483
+ weights = df [weight_column ] if weight_column else None
478
484
479
485
features = features if not encode_extra_cols else expand_features_encoded (df , features )
480
486
481
- dtrain = lgbm .Dataset (df [features ]. values , label = df [target ], feature_name = list (map (str , features )), weight = weights ,
482
- silent = True )
487
+ dtrain = lgbm .Dataset (df [features ], label = df [target ], feature_name = list (map (str , features )), weight = weights ,
488
+ silent = True , categorical_feature = categorical_features )
483
489
484
- bst = lgbm .train (params , dtrain , num_estimators )
490
+ bst = lgbm .train (params , dtrain , num_estimators , categorical_feature = categorical_features )
485
491
486
492
def p (new_df : pd .DataFrame , apply_shap : bool = False ) -> pd .DataFrame :
487
- col_dict = {prediction_column : bst .predict (new_df [features ]. values )}
493
+ col_dict = {prediction_column : bst .predict (new_df [features ])}
488
494
489
495
if apply_shap :
490
496
import shap
0 commit comments