lecrapaud 0.8.1__py3-none-any.whl → 0.8.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of lecrapaud might be problematic. Click here for more details.

@@ -135,10 +135,9 @@ class FeatureSelectionEngine:
135
135
  logger.info(f"Starting feature selection for TARGET_{target_number}...")
136
136
  clean_directory(self.fs_dir_target)
137
137
 
138
- # Let's start by removing extremly correlated features
139
- # This is needed to reduce nb of feature but also for methods such as anova or chi2 that requires independent features
140
- # TODO: we could also remove low variance features
141
- self.X = self.remove_constant_columns()
138
+ # Let's start by removing very low variance feature and extremly correlated features
139
+ # This is needed to reduce nb of feature but also for methods such as anova or chi2 that requires independent, non constant, non full 0 features
140
+ self.X = self.remove_low_variance_columns()
142
141
  features_uncorrelated, features_correlated = self.remove_correlated_features(
143
142
  90, vizualize=False
144
143
  )
@@ -353,34 +352,31 @@ class FeatureSelectionEngine:
353
352
  # Remove correlation
354
353
  # ------------------
355
354
 
356
- def remove_constant_columns(
357
- self,
358
- threshold: float = 0.99,
359
- ) -> pd.DataFrame:
355
+ def remove_low_variance_columns(self, threshold: float = 1e-10) -> pd.DataFrame:
360
356
  """
361
- Removes constant or almost constant columns from a DataFrame.
357
+ Removes columns with very low variance (including constant columns).
362
358
 
363
359
  Parameters:
364
- threshold (float): Max proportion for a single value (default 0.99 = 99%).
360
+ threshold (float): Minimum variance required to keep a column.
361
+ Default is 1e-10 to eliminate near-constant features.
365
362
 
366
363
  Returns:
367
- pd.DataFrame: Cleaned DataFrame.
364
+ pd.DataFrame: Cleaned DataFrame without low-variance columns.
368
365
  """
366
+ X = self.X
369
367
 
370
- to_drop = []
371
-
372
- for col in self.data.columns:
373
- value_counts = self.data[col].value_counts(dropna=False, normalize=True)
374
- if value_counts.empty:
375
- to_drop.append(col)
376
- elif value_counts.iloc[0] >= threshold:
377
- to_drop.append(col)
368
+ low_var_cols = [
369
+ col
370
+ for col in X.columns
371
+ if pd.api.types.is_numeric_dtype(X[col])
372
+ and np.nanvar(X[col].values) < threshold
373
+ ]
378
374
 
379
- if to_drop:
380
- logger.info(f"🔍 Removed {len(to_drop)} constant/almost constant columns:")
381
- logger.info(to_drop)
375
+ if low_var_cols:
376
+ logger.info(f"🧹 Removed {len(low_var_cols)} low-variance columns:")
377
+ logger.info(low_var_cols)
382
378
 
383
- return self.data.drop(columns=to_drop, errors="ignore")
379
+ return X.drop(columns=low_var_cols, errors="ignore")
384
380
 
385
381
  def remove_correlated_features(self, corr_threshold: int, vizualize: bool = False):
386
382
  X = self.X
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lecrapaud
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: Framework for machine and deep learning, with regression, classification and time series analysis
5
5
  License: Apache License
6
6
  Author: Pierre H. Gallet
@@ -24,7 +24,7 @@ lecrapaud/db/session.py,sha256=K9dTyXmO-aF_2r9RRHsDsbW9_zLNDaOcchXlpiv7cSo,2719
24
24
  lecrapaud/directories.py,sha256=t4PrnJR48MpDfBOTYTyGlDVMUr39mcaj7uCPTaocBRw,725
25
25
  lecrapaud/experiment.py,sha256=NwwGDZqUyvvRu5EDK3_Oh0_kF29bNIPDawVFFpzFvZM,2350
26
26
  lecrapaud/feature_engineering.py,sha256=U3YOftZBB3PEqGbu2aFY_3B3Ks9Hiu04UxixOkBz0UU,31168
27
- lecrapaud/feature_selection.py,sha256=v4azPcLs-xutvjlIWdTTgJu9vnT5Gpmg9Tb3hEeDqms,43681
27
+ lecrapaud/feature_selection.py,sha256=CUekyBet6AehobFJV_RWmKCOjMHKWadcXJUDb6FbRZM,43671
28
28
  lecrapaud/integrations/openai_integration.py,sha256=hHLF3fk5Bps8KNbNrEL3NUFa945jwClE6LrLpuMZOd4,7459
29
29
  lecrapaud/jobs/__init__.py,sha256=ZkrsyTOR21c_wN7RY8jPhm8jCrL1oCEtTsf3VFIlQiE,292
30
30
  lecrapaud/jobs/config.py,sha256=AmO0j3RFjx8H66dfKw_7vnshaOJb9Ox5BAZ9cwwLFMY,377
@@ -37,7 +37,7 @@ lecrapaud/speed_tests/test-gpu-resnet.ipynb,sha256=27Vu7nYwujYeh3fOxBNCnKJn3MXNP
37
37
  lecrapaud/speed_tests/test-gpu-transformers.ipynb,sha256=k6MBSs_Um1h4PykvE-LTBcdpbWLbIFST_xl_AFW2jgI,8444
38
38
  lecrapaud/speed_tests/tests.ipynb,sha256=RjI7LDHSsbadUkea_hT14sD7ivljtIQk4NB5McXJ1bE,3835
39
39
  lecrapaud/utils.py,sha256=Dy2uhK9cslzoqRHiIE6MdkxjNJWjmKmzGr6i7EYM28A,8106
40
- lecrapaud-0.8.1.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
41
- lecrapaud-0.8.1.dist-info/METADATA,sha256=-N9LIA9ueqU7d4-AlJ0Evl2KBxiZYrzGBz5oMZ9MQnY,11623
42
- lecrapaud-0.8.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
43
- lecrapaud-0.8.1.dist-info/RECORD,,
40
+ lecrapaud-0.8.3.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
41
+ lecrapaud-0.8.3.dist-info/METADATA,sha256=w6Nq7AP4_mybzw_dTveQm6PbAddeWMtYswdNe2qoVxc,11623
42
+ lecrapaud-0.8.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
43
+ lecrapaud-0.8.3.dist-info/RECORD,,