scitex_ml.utils
Scitex utils module.
- class scitex_ml.utils.DefaultDataset(*args: Any, **kwargs: Any)[source]
Apply transform for the first element of arrs_list
Example
n = 1024 n_chs = 19 X = np.random.rand(n, n_chs, 1000) T = np.random.randint(0, 4, size=(n, 1)) S = np.random.randint(0, 999, size=(n, 1)) Sr = np.random.randint(0, 4, size=(n, 1))
arrs_list = [X, T, S, Sr] transform = None ds = _DefaultDataset(arrs_list, transform=transform) len(ds) # 1024
- class scitex_ml.utils.LabelEncoder[source]
An extension of the sklearn.preprocessing.LabelEncoder that supports incremental learning. This means it can handle new classes without forgetting the old ones.
- classes_
Holds the label for each class.
- Type:
np.ndarray
- Example usage:
encoder = IncrementalLabelEncoder() encoder.fit(np.array([“apple”, “banana”])) encoded_labels = encoder.transform([“apple”, “banana”]) # This will give you the encoded labels
encoder.fit([“cherry”]) # Incrementally add “cherry” encoder.transform([“apple”, “banana”, “cherry”]) # Now it works, including “cherry”
# Now you can use inverse_transform with the encoded labels print(encoder.classes_) original_labels = encoder.inverse_transform(encoded_labels) print(original_labels) # This should print [‘apple’, ‘banana’]
- transform(y)[source]
Transform labels to normalized encoding.
- Parameters:
y (list, tuple, np.ndarray, pd.Series, pd.DataFrame, torch.Tensor) – The input labels.
- Returns:
The encoded labels as a NumPy array.
- Return type:
np.ndarray
- Raises:
ValueError – If the input contains new labels that haven’t been seen during fit.
- scitex_ml.utils.under_sample(y, replace=False)[source]
- Input:
Labels
- Returns:
Indices
Example
t = [‘a’, ‘b’, ‘c’, ‘b’, ‘c’, ‘a’, ‘c’] print(under_sample(t)) # [5 0 1 3 4 6] print(under_sample(t)) # [5 0 1 3 6 2]
Modules
This script defines scitex_ml.utils.grid_search |