API Reference / cli /

train.py

Train Command - Build and train machine learning models via CLI.

Functions

Func

parse_extra_args

Line 8
parse_extra_args(args)

Parse unrecognised command-line arguments into a keyword dictionary.

Leading dashes are stripped from each flag name. A flag followed by a non-flag token takes that token as its value, coerced to bool, int, or float when possible; a flag with no value becomes True.

Parameters

args
list of str
Raw leftover tokens, typically click.Context.args.

Returns

kwargs
dict
Mapping of flag name to parsed value.
python
>>> from tuiml.cli.train import parse_extra_args
>>> parse_extra_args(['--kfold', '10', '--strategy', 'mean', '--cv'])
{'kfold': 10, 'strategy': 'mean', 'cv': True}
Command

tuiml train

Line 89
tuiml train [OPTIONS]

Train a machine learning model, end to end or one stage at a time.

Loads a dataset, applies optional preprocessing and feature selection, fits the chosen algorithm, and reports metrics from a holdout split or cross-validation. The fitted model is saved and its ID and path are printed so later commands can reuse it. Pass --stage to run a single step of the workflow instead of the whole thing; unrecognised flags are forwarded to that stage as extra keyword arguments.

Train on a built-in dataset:

bash
$ tuiml train -a RandomForestClassifier -d iris -t class

Train on a CSV, save the model to a chosen path, and store the report:

bash
$ tuiml train -a SVC -d data.csv -t label --save-path model.pkl -o report.json

Add preprocessing and feature selection, then cross-validate:

bash
$ tuiml train -a LogisticRegression -d data.csv -t label -p StandardScaler -f SelectKBest --cv 10

Pass hyperparameters as JSON and fix the seed:

bash
$ tuiml train -a RandomForestClassifier -d iris -t class -P '{"n_estimators": 200}' --random-seed 42

Run one atomic stage against an existing model:

bash
$ tuiml train --stage partial_fit --model-id abc123 -d new_batch.csv -t label

Options

--algorithm, -a
Exact algorithm class name, e.g. RandomForestClassifier. Run "tuiml list" to browse.
--data, -d
Path to a data file (CSV/ARFF/JSON) or a built-in dataset name, e.g. iris.
--target, -t
Name of the target column in the data file. Built-in datasets define their own.
--preprocessing, -p
repeatable
Preprocessing step to apply, by exact class name. Repeatable; applied in the order given.
--feature-selection, -f
Feature selection method, by exact class name.
--cv
int
Number of cross-validation folds. Omit to use a single train/test split.
--test-size
float = 0.2
Fraction of the data held out for testing (default: 0.2).
--metrics, -m
repeatable
Metric to compute, by function name. Repeatable; defaults to metrics chosen for the task.
--preset
Preprocessing preset: minimal, fast, standard, full, or imbalanced.
--params, -P
Algorithm hyperparameters as a JSON object, e.g. '{"n_estimators": 200}'.
--random-seed
int
Random seed for reproducible splits and model fitting.
--output, -o
Write the full result record to this file as JSON.
--save-path
Path to save the trained model file. Defaults to a managed location.
--stage
Run a single atomic stage instead of the full workflow: 'init', 'fit', 'partial_fit', or 'cross_validate'.
--model-id
ID of a previously initialized or trained model to continue working with.
--model-path
File path of a previously initialized or trained model (alternative to --model-id).
--json-output
flag
Print the raw JSON result instead of the formatted summary.
--verbose, -v
flag
Echo the resolved configuration and re-raise full tracebacks on error.