Ahmedik95316 commited on
Commit
64ff698
·
verified ·
1 Parent(s): 57b1cee

Update features/feature_engineer.py

Browse files
Files changed (1) hide show
  1. features/feature_engineer.py +8 -1
features/feature_engineer.py CHANGED
@@ -322,7 +322,14 @@ class AdvancedFeatureEngineer(BaseEstimator, TransformerMixin):
322
  # Apply feature selection to names if applicable
323
  if self.feature_selector is not None:
324
  selected_indices = self.feature_selector.get_support()
325
- self.feature_names_ = [name for i, name in enumerate(self.feature_names_) if selected_indices[i]]
 
 
 
 
 
 
 
326
 
327
  def _calculate_feature_importance(self):
328
  """Calculate feature importance scores"""
 
322
  # Apply feature selection to names if applicable
323
  if self.feature_selector is not None:
324
  selected_indices = self.feature_selector.get_support()
325
+ # Add bounds checking to prevent IndexError
326
+ if len(selected_indices) == len(self.feature_names_):
327
+ self.feature_names_ = [name for i, name in enumerate(self.feature_names_) if selected_indices[i]]
328
+ else:
329
+ logger.warning(f"Mismatch: {len(selected_indices)} selected_indices vs {len(self.feature_names_)} feature_names")
330
+ # Use the shorter length to avoid index errors
331
+ min_length = min(len(selected_indices), len(self.feature_names_))
332
+ self.feature_names_ = [name for i, name in enumerate(self.feature_names_[:min_length]) if i < len(selected_indices) and selected_indices[i]]
333
 
334
  def _calculate_feature_importance(self):
335
  """Calculate feature importance scores"""