Spaces:
Sleeping
Sleeping
Upload utils/preprocessing.py with huggingface_hub
Browse files- utils/preprocessing.py +17 -0
utils/preprocessing.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def filter_low_variance_features(X: np.ndarray, threshold: float = 0.05) -> np.ndarray:
|
| 5 |
+
variances = np.var(X, axis=0)
|
| 6 |
+
return np.where(variances >= threshold)[0]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def filter_high_correlation_features(X: np.ndarray, threshold: float = 0.95) -> np.ndarray:
|
| 10 |
+
corr = np.corrcoef(X.T)
|
| 11 |
+
keep = np.ones(X.shape[1], dtype=bool)
|
| 12 |
+
for i in range(X.shape[1]):
|
| 13 |
+
if keep[i]:
|
| 14 |
+
for j in range(i + 1, X.shape[1]):
|
| 15 |
+
if abs(corr[i, j]) > threshold:
|
| 16 |
+
keep[j] = False
|
| 17 |
+
return np.where(keep)[0]
|