Skip to content

Commit 7f7afe7

Browse files
committed
[#162] Integrate LightGBM with training step 3
1 parent 34b1a26 commit 7f7afe7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

hlink/linking/training/link_step_save_model_metadata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def _run(self):
104104
zip(true_column_names, true_categories, weights, gains),
105105
"feature_name: string, category: int, weight: double, average_gain_per_split: double",
106106
).sort("feature_name", "category")
107+
elif model_type == "lightgbm":
108+
num_splits = model.getFeatureImportances("split")
109+
total_gains = model.getFeatureImportances("gain")
110+
label = "Feature importances (number of splits and total gains)"
111+
112+
features_df = self.task.spark.createDataFrame(
113+
zip(true_column_names, true_categories, num_splits, total_gains),
114+
"feature_name: string, category: int, num_splits: double, total_gain: double",
115+
).sort("feature_name", "category")
107116
else:
108117
try:
109118
feature_imp = model.coefficients

hlink/tests/training_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ def test_step_3_with_lightgbm_model(
486486

487487
training.run_all_steps()
488488

489+
importances_df = spark.table("training_feature_importances")
490+
assert importances_df.columns == [
491+
"feature_name",
492+
"category",
493+
"num_splits",
494+
"total_gain",
495+
]
496+
489497

490498
@requires_lightgbm
491499
def test_lightgbm_with_interacted_features(
@@ -536,6 +544,14 @@ def test_lightgbm_with_interacted_features(
536544

537545
training.run_all_steps()
538546

547+
importances_df = spark.table("training_feature_importances")
548+
assert importances_df.columns == [
549+
"feature_name",
550+
"category",
551+
"num_splits",
552+
"total_gain",
553+
]
554+
539555

540556
@requires_xgboost
541557
def test_step_3_with_xgboost_model(

0 commit comments

Comments
 (0)