From 1868ad6177d50f66c593454867380c8c2afd6fcf Mon Sep 17 00:00:00 2001 From: Bagus Tris Atmaja Date: Fri, 30 Aug 2024 17:49:17 +0900 Subject: [PATCH] print and save result of feature importance --- nkululeko/feat_extract/feats_analyser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nkululeko/feat_extract/feats_analyser.py b/nkululeko/feat_extract/feats_analyser.py index e7d93459..3f9fef92 100644 --- a/nkululeko/feat_extract/feats_analyser.py +++ b/nkululeko/feat_extract/feats_analyser.py @@ -205,7 +205,7 @@ def analyse(self): model, permutation ) elif model_s == "xgr": - from xgboost import XGBClassifier + from xgboost import XGBRegressor model = XGBRegressor() result_importances[model_s] = self._get_importance( @@ -270,9 +270,14 @@ def analyse(self): ) ) + # print feature importance values to file and debug and save to result + self.util.debug(f"List of importance feature {model_name}: \n{df_imp['feats'].values.tolist()}") # result file res_dir = self.util.get_path("res_dir") filename = f"_EXPL_{model_name}" + feats_path = f"{res_dir}{self.util.get_exp_name()}_{filename}_fi.txt" + df_imp.to_csv(feats_path) + self.util.debug(f"Saved feature importance values to {feats_path}") if permutation: filename += "_perm" filename = f"{res_dir}{self.util.get_exp_name(only_data=True)}{filename}_{model_name}.txt"