API Reference¶
MELITE exposes a focused public Python API, defined by melite.__all__.
Complete classifier evaluation is performed through the command-line interface
(CLI) using melite run.
The Python API complements this workflow with programmatic access to configuration, dataset loading, evaluation-evidence visualization, inference, and version information.
from melite import predict
from melite import Config
from melite import load_datasets
from melite import plot_f1_macro_evidence
from melite import __version__
MELITE is currently pre-stable. During the 0.2.x series, the documented symbols are supported for the current release but may evolve before version 1.0.
predict¶
Run inference with a model artifact produced by melite export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str or Path
|
Path to a |
required |
X
|
ndarray
|
Numeric feature matrix of shape |
required |
return_proba
|
bool
|
Whether to request class probabilities when the loaded model supports
|
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with the following keys:
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If |
Notes
This function is intended for fitted model artifacts created by
melite export.
Examples:
>>> import numpy as np
>>> from melite import predict
>>> X_new = np.random.default_rng(42).random((4, 5)).astype(np.float32)
>>> result = predict("output/Model_SVC_sample_tabular.pkl", X_new)
>>> result["predictions"].shape == (4,)
True
>>> result["n_samples"]
4
Config¶
Configuration container for loading, merging, normalizing, and inspecting MELITE runtime settings.
Loads defaults from melite/config_default.toml. If user_config is
provided, its values are merged over the defaults — user values win and
missing keys fall back to defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smoke
|
bool
|
Whether to use reduced CV/search settings for lightweight execution
checks. Default is |
False
|
user_config
|
Path or None
|
Optional TOML configuration file merged over packaged defaults.
Default is |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
SMOKE |
bool
|
Whether the instance was created in smoke mode. |
PATHS |
dict
|
Dictionary with keys |
RESULTS_FILE |
str
|
Path to the TXT results file ( |
RANDOM_STATE |
int
|
Canonical global random seed used by MELITE runtime and evaluation
components. Default is |
N_TRIALS |
int
|
Optimization trial budget. Normal mode uses the effective
|
DATASETS |
dict
|
Normalized dataset registry keyed by user-defined dataset id. Each
entry contains |
ACTIVE_CLASSIFIERS |
list of str
|
Classifier keys to include in the evaluation (e.g. |
CV_CONFIG |
dict
|
Cross-validation settings with keys |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the supplied user configuration file does not exist. |
ValueError
|
If a user configuration uses the obsolete |
Examples:
Default configuration:
>>> from melite import Config
>>> cfg = Config()
>>> cfg.RANDOM_STATE
42
Smoke mode:
>>> cfg = Config(smoke=True)
>>> cfg.CV_CONFIG["n_splits"]
3
load_datasets¶
Load every normalized dataset in a MELITE configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Normalized MELITE configuration containing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary keyed by user-defined dataset id. Each dataset value is a dictionary containing:
Dataset ids are not interpreted as method, representation, reduction,
or classifier names. For NPZ, the configured |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a configured dataset file or authoritative label file does not exist. |
ValueError
|
If an NPZ dataset violates its feature or label consistency contract,
or if a CSV cannot be parsed, lacks its configured label or any feature
columns, contains an |
Examples:
>>> import pandas as pd
>>> from pathlib import Path
>>> from tempfile import TemporaryDirectory
>>> from melite import Config, load_datasets
>>> with TemporaryDirectory() as temporary_directory:
... root = Path(temporary_directory).resolve()
... data_path = root / "sample_tabular.csv"
... config_path = root / "config.toml"
... table = pd.DataFrame(
... {
... "feature_a": [0.0, 1.0],
... "feature_b": [1.0, 0.0],
... "Outcome": ["class_a", "class_b"],
... }
... )
... table.to_csv(data_path, index=False)
... config_text = (
... "[datasets.sample_tabular]\n"
... f'path = "{data_path.as_posix()}"\n'
... 'label_column = "Outcome"\n'
... 'description = "Neutral numeric example"\n'
... )
... _ = config_path.write_text(config_text, encoding="utf-8")
... cfg = Config(user_config=config_path)
... loaded = load_datasets(cfg)
... loaded["sample_tabular"]["X"].shape
(2, 2)
plot_f1_macro_evidence¶
Visualize preserved outer-CV F1-macro evidence.
The supplied scores are plotted directly, and the classifier previously selected by the evaluation workflow is explicitly marked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_scores
|
Mapping[str, Sequence[float]]
|
Mapping from classifier name to supplied outer-CV F1-macro scores.
Each score sequence must be numeric, one-dimensional, non-empty,
finite, and within |
required |
selected_classifier
|
str
|
Classifier previously selected by the evaluation workflow. This function marks that classifier but does not recompute selection. |
required |
dataset_id
|
str
|
User-defined dataset identifier shown in the figure title. |
required |
save_to
|
Path or str or None
|
Optional destination path. Parent directories are created
automatically, and Matplotlib infers the output format from the path
or extension. If |
None
|
smoke
|
bool
|
Whether to annotate the figure as smoke-mode evidence. This affects presentation only. |
False
|
Returns:
| Type | Description |
|---|---|
Figure
|
Newly created figure. The function does not show or close it; the caller owns the returned figure and is responsible for displaying or closing it when appropriate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
This function performs no fitting, hyperparameter tuning, cross-validation,
or classifier selection. Supplied scores are visualized directly. The mean
and population standard deviation (ddof=0) are shown. Classifiers
follow the iteration order of the supplied mapping. Horizontal jitter uses
a deterministic local random-number generator and affects display position
only; supplied F1-macro values are not modified.
Saved raster output uses 300 dpi; vector formats follow Matplotlib's behavior. Filesystem and Matplotlib saving errors propagate to the caller.
Examples:
>>> import matplotlib.pyplot as plt
>>> from melite import plot_f1_macro_evidence
>>> scores = {
... "SVC": [0.78, 0.82, 0.80],
... "RandomForestClassifier": [0.81, 0.84, 0.83],
... }
>>> fig = plot_f1_macro_evidence(
... scores,
... selected_classifier="RandomForestClassifier",
... dataset_id="sample_tabular",
... )
>>> fig.axes[0].get_ylabel()
'Outer-CV F1-macro'
>>> plt.close(fig)
__version__¶
Current MELITE package version.
For workflow-oriented examples, configuration, and the evaluation contract, see Usage.