High-Level API

The simple module provides high-level APIs for quick experimentation.

Model Builders

Simple Trainer

High-level training API for FIT framework.

This module provides simple, one-line training functions that handle all the boilerplate while remaining flexible for advanced use cases.

class fit.simple.trainer.SimpleTrainer(model, data: tuple | DataLoader, validation_data: tuple | DataLoader | None = None, loss: str | Any = 'auto', optimizer: str | Any = 'adam', metrics: List[str] | None = None, callbacks: List[str] | None = None, **kwargs)[source]

Bases: object

High-level trainer that handles all the boilerplate.

Makes training as simple as: trainer = SimpleTrainer(model, data) trainer.fit()

__init__(model, data: tuple | DataLoader, validation_data: tuple | DataLoader | None = None, loss: str | Any = 'auto', optimizer: str | Any = 'adam', metrics: List[str] | None = None, callbacks: List[str] | None = None, **kwargs)[source]

Initialize the simple trainer.

Parameters:
  • model – The model to train

  • data – Training data as (X, y) tuple or DataLoader

  • validation_data – Validation data (optional)

  • loss – Loss function (‘auto’, ‘mse’, ‘crossentropy’, or loss object)

  • optimizer – Optimizer (‘adam’, ‘sgd’, ‘sam’, or optimizer object)

  • metrics – List of metrics to track [‘accuracy’, ‘loss’]

  • callbacks – List of callback names [‘early_stopping’, ‘lr_scheduler’]

  • **kwargs – Additional arguments (lr, batch_size, etc.)

fit(epochs: int = 100, verbose: int = 1)[source]

Train the model.

Parameters:
  • epochs – Number of epochs to train

  • verbose – Verbosity level (0=silent, 1=progress bar, 2=one line per epoch)

Returns:

Training history dictionary

evaluate(test_data: tuple | DataLoader) Dict[str, float][source]

Evaluate the model on test data.

Parameters:

test_data – Test data as (X, y) tuple or DataLoader

Returns:

Dictionary with evaluation metrics

predict(X)[source]

Make predictions on new data.

Parameters:

X – Input data

Returns:

Predictions as numpy array

save(filepath: str)[source]

Save the trained model.

load(filepath: str)[source]

Load a trained model.

fit.simple.trainer.fit_classifier(model, train_data, validation_data=None, epochs=100, lr=0.001, batch_size=32, optimizer='adam', **kwargs)[source]

Quick function to train a classification model.

Parameters:
  • model – Model to train

  • train_data – Training data as (X, y) tuple

  • validation_data – Validation data (optional)

  • epochs – Number of epochs

  • lr – Learning rate

  • batch_size – Batch size

  • optimizer – Optimizer name or instance

  • **kwargs – Additional arguments

Returns:

Trained model and training history

fit.simple.trainer.fit_regressor(model, train_data, validation_data=None, epochs=100, lr=0.001, batch_size=32, optimizer='adam', **kwargs)[source]

Quick function to train a regression model.

Parameters:
  • model – Model to train

  • train_data – Training data as (X, y) tuple

  • validation_data – Validation data (optional)

  • epochs – Number of epochs

  • lr – Learning rate

  • batch_size – Batch size

  • optimizer – Optimizer name or instance

  • **kwargs – Additional arguments

Returns:

Trained model and training history

fit.simple.trainer.quick_train(model, X, y, **kwargs)[source]

Ultra-simple training function.

Parameters:
  • model – Model to train

  • X – Input features

  • y – Target labels

  • **kwargs – Training parameters

Returns:

Trained model

Quick Data Loading

Quick dataset loaders for common machine learning datasets.

This module provides simple functions to load and preprocess popular datasets, making it easy to get started with machine learning experiments.

fit.simple.data.load_dataset(name: str, batch_size: int = 32, validation_split: float = 0.2, test_split: float | None = None, shuffle: bool = True, normalize: bool = True, flatten: bool = False, data_dir: str = './data', **kwargs) Dict[str, DataLoader][source]

Load a dataset by name with automatic preprocessing.

Parameters:
  • name – Dataset name (‘mnist’, ‘cifar10’, ‘boston’, ‘iris’, ‘xor’)

  • batch_size – Batch size for DataLoaders

  • validation_split – Fraction of training data to use for validation

  • test_split – Fraction of data to use for testing (if dataset doesn’t have test split)

  • shuffle – Whether to shuffle the data

  • normalize – Whether to normalize features

  • flatten – Whether to flatten image data

  • data_dir – Directory to store/cache datasets

  • **kwargs – Additional dataset-specific arguments

Returns:

Dictionary with ‘train’, ‘val’, and optionally ‘test’ DataLoaders

Examples

# Load MNIST >>> data = load_dataset(‘mnist’, batch_size=64) >>> train_loader = data[‘train’] >>> val_loader = data[‘val’]

# Load with custom split >>> data = load_dataset(‘iris’, validation_split=0.3, test_split=0.2)

fit.simple.data.quick_split(X: ndarray, y: ndarray, validation_split: float = 0.2, test_split: float | None = None, shuffle: bool = True, batch_size: int = 32) Dict[str, DataLoader][source]

Quickly split any dataset into train/val/test loaders.

Parameters:
  • X – Input features

  • y – Target labels

  • validation_split – Fraction for validation

  • test_split – Fraction for test (optional)

  • shuffle – Whether to shuffle data

  • batch_size – Batch size for loaders

Returns:

Dictionary with DataLoaders

Examples

# Simple train/val split >>> loaders = quick_split(X, y, validation_split=0.2)

# Train/val/test split >>> loaders = quick_split(X, y, validation_split=0.2, test_split=0.1)

fit.simple.data.get_sample_data(dataset_name: str) Tuple[ndarray, ndarray][source]

Get a small sample of data for quick testing.

Parameters:

dataset_name – Name of dataset

Returns:

Tuple of (X, y) arrays

Examples

# Get XOR data for testing >>> X, y = get_sample_data(‘xor’) >>> print(X.shape, y.shape) # (4, 2) (4,)

fit.simple.data.load_for_classification(dataset_name: str, **kwargs)[source]

Load a dataset specifically configured for classification.

fit.simple.data.load_for_regression(dataset_name: str, **kwargs)[source]

Load a dataset specifically configured for regression.

fit.simple.data.load_tiny(dataset_name: str, max_samples: int = 1000, **kwargs)[source]

Load a tiny version of a dataset for quick experimentation.