ARFF (Attribute-Relation File Format) reader and writer.

ARFF is a self-documenting text format: a header naming each attribute and its type, followed by comma-separated rows. It is the format every dataset bundled with TuiML ships in, and this module also defines Dataset, the container that every loader in this package returns.

Classes

Dataset

class datasets.loaders.arff.Dataset

Container for loaded datasets with support for features and targets.

Provides a standardized way to access data and metadata across different file formats and data sources.

Attributes

X
np.ndarray
Feature matrix of shape (n_samples, n_features).
y
np.ndarray or None = None
Target values (labels) of shape (n_samples,).
feature_names
List[str]
List of attribute names for the features.
target_names
List[str] or None
List of class names for the target (for classification tasks).
name
str = "dataset"
Name of the dataset, often derived from filename or @relation tag.
description
str
Textual description or comments included in the data file.
python
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> data.X.shape
(150, 4)
>>> data.feature_names
['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
>>> df = data.to_pandas()
>>> df.shape
(150, 5)

Methods

n_samples (self) -> int

Total number of observations in the dataset.

n_features (self) -> int

Total number of input features (attributes).

shape (self) -> Tuple[int, int]

Dimensionality of the feature matrix (n_samples, n_features).

__repr__ (self) -> str
to_pandas (self, include_target: bool=True)

Convert Dataset to pandas DataFrame.

Functions

Func

load_arff

Line 91
load_arff(filepath: Union[str, Path], target_column: int=...) -> Dataset

Load data from ARFF (Attribute-Relation File Format) files.

ARFF supports rich metadata, dense and sparse data, and explicit type declarations.

Parameters

filepath
Union[str, Path]
Path to the ARFF file to be loaded.
target_column
int = -1

The index of the column to treat as the target variable:

  • -1: Use the last column (standard for most ARFFs)
  • int: Use specific zero-based index
  • None: Do not extract a target (X will contain all columns)

Returns

Dataset
Standardized dataset object containing data and metadata.
python
>>> from tuiml.datasets.loaders import load_arff
>>> data = load_arff('iris.arff')
>>> X, y = data
>>> print(X.shape)
(150, 4)
Func

save_arff

Line 410
save_arff(filepath: Union[str, Path], data: np.ndarray, feature_names: Optional[List[str]]=None, target: Optional[np.ndarray]=None, target_names: Optional[List[str]]=None, relation: str='data')

Save data to ARFF (Attribute-Relation File Format).

Parameters

filepath
Union[str, Path]
Output path where the ARFF file will be saved.
data
np.ndarray
Feature matrix to save.
feature_names
List[str] or None = None
Names for the features. If None, generic names like attr0, attr1 will be used.
target
np.ndarray or None = None
Target values to include in the file.
target_names
List[str] or None = None
Names for target classes (for nominal attributes).
relation
str = "data"
Name of the relation (dataset name) in the ARFF header.
python
>>> import numpy as np
>>> from tuiml.datasets.loaders import save_arff
>>> X = np.random.rand(10, 2)
>>> save_arff('output.arff', X, feature_names=['x1', 'x2'])