From e555c011bb87454a328d21b8e06d1dd0c3becfa3 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Wed, 6 Nov 2024 05:25:16 -0800 Subject: [PATCH] add uniform feature subsampling to gam_shap --- imodels/algebraic/gam_shap.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imodels/algebraic/gam_shap.py b/imodels/algebraic/gam_shap.py index 573fda07..7bf53223 100644 --- a/imodels/algebraic/gam_shap.py +++ b/imodels/algebraic/gam_shap.py @@ -30,9 +30,13 @@ def fit(self, X, y): for _ in range(self.n_estimators): # Randomly select a subset of features + if isinstance(self.feature_fraction, float): + n_features = max(1, int(self.feature_fraction * n_features)) + elif self.feature_fraction == 'uniform': + n_features = rng.integers(1, n_features + 1) feature_subset = rng.choice( n_features, - size=int(self.feature_fraction * n_features), + size=n_features, replace=False ) self.feature_subsets.append(feature_subset)