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

__init__(arrs_list, transform=None)[source]
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’]

__init__()[source]
fit(y)[source]

Fit the label encoder with an array of labels, incrementally adding new classes.

Parameters:

y (list, tuple, np.ndarray, pd.Series, pd.DataFrame, torch.Tensor) – The input labels.

Returns:

The instance itself.

Return type:

IncrementalLabelEncoder

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.

inverse_transform(y)[source]

Transform labels back to original encoding.

Parameters:

y (np.ndarray) – The encoded labels as a NumPy array.

Returns:

The original labels as a NumPy array.

Return type:

np.ndarray

scitex_ml.utils.check_params(model, tgt_name=None, show=False)[source]
scitex_ml.utils.format_samples_for_sktime(X)[source]

X.shape: (n_samples, n_chs, seq_len)

scitex_ml.utils.merge_labels(*ys, to_int=False)[source]
scitex_ml.utils.sliding_window_data_augmentation(x, window_size_pts)[source]
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]

scitex_ml.utils.verify_n_gpus(n_gpus)[source]

Modules

grid_search

This script defines scitex_ml.utils.grid_search