Skip to main content
. 2024 Jun 25;14(13):1344. doi: 10.3390/diagnostics14131344
Algorithm 1. To treat imbalance
1 Reshape Data
2  n_samples, *input_shape = X.shape
3  X_reshaped = reshape(X, (n_samples, -1))
4 Initialize RandomOverSampler
5  ros = RandomOverSampler(random_state=random_state)
6 Resample Dataset
7   X_resampled = reshape(X_resampled, (len(X_resampled), *input_shape))
8 Compute Class Weights
9   class_counts = bincount(y_resampled)
10   class_weights = 1.0 / class_counts
11   class_weights_tensor = convert_to_tensor(class_weights, dtype=float32)