utils
TemporalScope/src/temporalscope/partition/single_target/utils.py
This module provides utility functions for single-target partitioning operations, including validation and computation of train/test/validation split percentages.
| FUNCTION | DESCRIPTION |
|---|---|
determine_partition_scheme |
Determine partition scheme based on user inputs. |
print_config |
Print a configuration as a table with validation for allowed data types. |
validate_cardinality |
Validate dataset cardinality for the partitioning configuration. |
validate_percentages |
Validate and compute train, test, and validation percentages. |
determine_partition_scheme
determine_partition_scheme(
num_partitions: Optional[int],
window_size: Optional[int],
total_rows: int,
stride: Optional[int],
) -> Tuple[str, int, int]
Determine partition scheme based on user inputs.
This function calculates num_partitions or window_size based on the dataset size.
| PARAMETER | DESCRIPTION |
|---|---|
num_partitions
|
Number of partitions, optional.
TYPE:
|
window_size
|
Size of each partition, optional.
TYPE:
|
total_rows
|
Total number of rows in the dataset.
TYPE:
|
stride
|
Number of rows to skip between partitions. Defaults to
TYPE:
|
num_partitions
|
TYPE:
|
window_size
|
TYPE:
|
total_rows
|
TYPE:
|
stride
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str, int, int]
|
Tuple containing the partition scheme ("num_partitions" or "window_size"), the determined number of partitions, and window size. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If both |
Source code in src/temporalscope/partition/single_target/utils.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
print_config
print_config(config: dict) -> None
Print a configuration as a table with validation for allowed data types.
This function ensures that all values in the configuration are of allowed types
(int, float, bool, str). It raises an error for any invalid types and then
prints the configuration as a table.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration dictionary with parameter names as keys and their values.
TYPE:
|
config
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If any value in the config dictionary is not an allowed type. |
Source code in src/temporalscope/partition/single_target/utils.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
validate_cardinality
validate_cardinality(
num_partitions: int, window_size: int, total_rows: int
) -> None
Validate dataset cardinality for the partitioning configuration.
| PARAMETER | DESCRIPTION |
|---|---|
num_partitions
|
Number of partitions.
TYPE:
|
window_size
|
Size of each partition.
TYPE:
|
total_rows
|
Total number of rows in the dataset.
TYPE:
|
num_partitions
|
TYPE:
|
window_size
|
TYPE:
|
total_rows
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If dataset cardinality is insufficient for the configuration. |
Source code in src/temporalscope/partition/single_target/utils.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
validate_percentages
validate_percentages(
train_pct: float,
test_pct: Optional[float],
val_pct: Optional[float],
precision: float = 1e-06,
) -> Tuple[float, float, float]
Validate and compute train, test, and validation percentages.
This function ensures percentages are within the range [0, 1], computes missing values, and validates that their sum equals 1.0.
| PARAMETER | DESCRIPTION |
|---|---|
train_pct
|
Percentage of data allocated for training.
TYPE:
|
test_pct
|
Percentage of data allocated for testing.
TYPE:
|
val_pct
|
Percentage of data allocated for validation.
TYPE:
|
precision
|
Tolerance for floating-point imprecision. Default is 1e-6.
TYPE:
|
train_pct
|
TYPE:
|
test_pct
|
TYPE:
|
val_pct
|
TYPE:
|
precision
|
(Default value = 1e-6)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[float, float, float]
|
Tuple of validated percentages (train_pct, test_pct, val_pct). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If percentages are invalid or do not sum to 1.0. |
Source code in src/temporalscope/partition/single_target/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |