Skip to content

Commit

Permalink
print and save result of feature importance
Browse files Browse the repository at this point in the history
  • Loading branch information
bagustris committed Aug 30, 2024
1 parent c5f7935 commit 1868ad6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nkululeko/feat_extract/feats_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1868ad6

Please sign in to comment.