ictonyx.data
Data handlers and loading utilities.
- class ictonyx.data.DataHandler[source]
Bases:
ABCAbstract base class for all data handlers.
Provides a consistent interface regardless of data source. Handlers that load from the file system should inherit from
FileDataHandlerinstead of this class directly.All subclasses must implement
load(),data_type, andreturn_format. The returned dict fromload()must have keys'train_data','val_data', and'test_data', each a(X, y)tuple orNone.
- class ictonyx.data.ImageDataHandler(data_path, image_size, batch_size=32, seed=42, color_mode='rgb', val_split=0.2, test_split=0.1)[source]
Bases:
FileDataHandlerData handler for image classification datasets in directory format.
Expects a directory structure where each subdirectory is a class label containing image files. Images are loaded, resized, normalized to [0, 1], and split into train/val/test sets.
Requires TensorFlow for image preprocessing. Install with
pip install tensorflow.- Parameters:
data_path (str) – Path to the root directory containing class subdirectories.
image_size (Tuple[int, int]) – Target
(height, width)for resizing, e.g.(64, 64).color_mode (str) –
'rgb'(3 channels) or'grayscale'(1 channel). Default'rgb'.batch_size (int)
seed (int)
val_split (float)
test_split (float)
- Raises:
ValueError – If the path is not a directory, contains no class subdirectories, or no valid image files are found.
- __init__(data_path, image_size, batch_size=32, seed=42, color_mode='rgb', val_split=0.2, test_split=0.1)[source]
Initialize the image data handler.
- Parameters:
data_path (str) – Path to directory containing class subdirectories.
image_size (Tuple[int, int]) –
(height, width)tuple for resizing images.batch_size (int) – Batch size for the datasets. Default 32.
seed (int) – Random seed for reproducibility. Default 42.
color_mode (str) –
'rgb'(default) or'grayscale'.val_split (float) – Fraction of data for validation. Default 0.2.
test_split (float) – Fraction of data for test. Default 0.1.
- class ictonyx.data.TabularDataHandler(data=None, target_column=None, features=None, sep=',', header=0, **kwargs)[source]
Bases:
FileDataHandlerData handler for structured tabular data from CSV files or DataFrames.
Loads data, validates columns, and splits into train/val/test sets. Supports both file-path and in-memory DataFrame initialization.
- Parameters:
data (str | DataFrame) – Path to a CSV file, or a
pd.DataFrame.target_column (str | None) – Name of the column containing labels.
features (List[str] | None) – Optional list of feature column names. If
None, all columns excepttarget_columnare used.sep (str) – CSV delimiter (only used for file paths). Default
','.header (int) – Header row number (only used for file paths). Default 0.
- Raises:
ValueError – If
dataortarget_columnis missing, or if the target column is not found in the data.TypeError – If
datais neither a string nor a DataFrame.
- __init__(data=None, target_column=None, features=None, sep=',', header=0, **kwargs)[source]
Initialize the tabular data handler.
- Parameters:
data (str | DataFrame) – Path to CSV file OR a pandas DataFrame object.
target_column (str | None) – Name of the target column.
features (List[str] | None) – List of feature column names (None = all except target).
sep (str) – CSV separator (only used if data is a path).
header (int) – Header row number (only used if data is a path).
**kwargs – Captures legacy ‘data_path’ argument.
- class ictonyx.data.TextDataHandler(data_path, text_column='text', label_column='label', max_features=10000, val_split=0.1, test_split=0.2)[source]
Bases:
FileDataHandlerFramework-agnostic text classification data handler.
Converts raw text to TF-IDF feature vectors compatible with all three model wrappers (Keras, PyTorch, sklearn). Does not require TensorFlow.
Requires scikit-learn:
pip install ictonyx[sklearn]- Parameters:
data_path (str) – Path to a CSV file containing text and label columns.
text_column (str) – Name of the column containing raw text. Default
'text'.label_column (str) – Name of the column containing labels. Default
'label'.max_features (int) – Maximum number of TF-IDF features. Default 10000.
val_split (float) – Fraction of training data to use for validation. Default 0.1.
test_split (float) – Fraction of all data to hold out for testing. Default 0.2.
- class ictonyx.data.TimeSeriesDataHandler(data_path, lookback=10, sequence_length=None, value_column='value', target_column=None, stride=1, val_split=0.1, test_split=0.2)[source]
Bases:
FileDataHandlerFramework-agnostic time series data handler using NumPy sliding windows.
Creates overlapping input windows from a univariate or multivariate time series. Compatible with all three model wrappers (Keras, PyTorch, sklearn). Does not require TensorFlow.
- Parameters:
data_path (str) – Path to a CSV file containing time series data.
lookback (int) – Number of time steps in each input window.
value_column (str) – Name of the column to use as the target series. Default
'value'.target_column (str | None) – Name of the column to predict. If
None, usesvalue_columnshifted by one step (next-step prediction). DefaultNone.stride (int) – Step between consecutive windows. Default 1.
val_split (float) – Fraction of data to use for validation (chronological). Default 0.1.
test_split (float) – Fraction of data to hold out for testing (chronological, taken from the end). Default 0.2.
sequence_length (int | None)
- class ictonyx.data.ArraysDataHandler(X, y, X_test=None, y_test=None, val_split=0.1, test_split=0.2)[source]
Bases:
DataHandlerData handler for pre-loaded in-memory arrays.
Use this when data is already available as numpy arrays or Python lists, bypassing file I/O entirely. This is the handler used when passing
(X, y)tuples tovariability_study().- Parameters:
- Raises:
ValueError – If
Xandyhave different lengths.
- __init__(X, y, X_test=None, y_test=None, val_split=0.1, test_split=0.2)[source]
Data handler for pre-loaded in-memory arrays.
Use this when data is already available as numpy arrays or Python lists, bypassing file I/O entirely. Optionally accepts a pre-held-out test set; if provided, it is passed through unchanged and only a train/val split is performed on the training arrays.
- Parameters:
X (ndarray | List | Any) – Feature array or list. Converted to
np.ndarrayon init.y (ndarray | List | Any) – Label array or list. Must have the same length as
X.X_test (ndarray | List | Any | None) – Optional pre-held-out test features. If provided,
load()will not carve a test set fromX/y.y_test (ndarray | List | Any | None) – Optional pre-held-out test labels. Required if
X_testis provided.val_split (float) – Default validation fraction passed to
load()0.1. (when not overridden there. Default)
test_split (float) – Default test fraction passed to
load()0.2. (when not overridden there. Default)
- Raises:
ValueError – If
Xandyhave different lengths.ValueError – If exactly one of
X_test/y_testis provided.ValueError – If
X_testandy_testhave different lengths.
- load(test_split=None, val_split=None, random_state=42, **kwargs)[source]
Split the pre-loaded arrays.
If X_test and y_test were provided at construction, they are used as the test set directly and only a train/val split is performed. Otherwise, test_split is carved out of the provided arrays first.
- Parameters:
test_split (float | None) – Fraction to reserve for test. Defaults to the value passed to
__init__(default0.2). Pass0to skip the test split.val_split (float | None) – Fraction to reserve for validation. Defaults to the value passed to
__init__(default0.1).random_state (int) – Seed for reproducibility. Default
42.kwargs (Any)
- Return type:
- ictonyx.data.auto_resolve_handler(data, target_column=None, **kwargs)[source]
Factory function to automatically detect and initialize the appropriate DataHandler.
- Parameters:
data (str | DataFrame | Tuple[ndarray, ndarray] | Any) – The input data. Supported formats: - str: Path to a directory (Images) - str: Path to a CSV file (Tabular, Text, or TimeSeries) - pd.DataFrame: Data object (Tabular) - tuple: (X, y) arrays (Arrays)
target_column (str | None) – Name of target column (Required for DataFrame/Tabular).
**kwargs – Additional arguments passed to the specific handler constructor (e.g., ‘image_size’, ‘text_column’, ‘sequence_length’).
- Returns:
An initialized instance of the appropriate handler.
- Return type:
- Raises:
ValueError – If handler cannot be determined or required args missing.
FileNotFoundError – If string path does not exist.