GalaxySpectrumClassifier requires Python 3.13 or newer. The package pulls in
the scientific Python stack used by the trainers, including pandas,
scikit-learn, torch, skorch, and torchvision.
The Python package can be installed from PyPI:
python -m pip install GalaxySpectrumClassifierTo install directly from a checkout of this repository:
git clone git@github.com:ssciwr/GalaxySpectrumClassifier.git
cd GalaxySpectrumClassifier
python -m pip install .If you want to contribute to the development of GalaxySpectrumClassifier, we recommend
the following editable installation from this repository:
git clone git@github.com:ssciwr/GalaxySpectrumClassifier.git
cd GalaxySpectrumClassifier
python -m pip install --editable .[tests]Having done so, the test suite can be run using pytest:
python -m pytestGalaxySpectrumClassifier provides a small set of configurable building blocks
for training galaxy-spectrum classifiers and related tabular models:
TabularDatasetpresents a directory of tabular files as one indexed dataset.SimpleTrainerfits models after converting a dataset to fullX, yarrays.EpochTrainertrains torch modules over repeated epochs throughskorch.
Most objects can be created directly from dictionaries, which makes YAML files a
convenient way to describe an experiment. The configs/ directory contains
examples for sklearn and skorch-based training.
import yaml
from GalaxySpectrumClassifier import SimpleTrainer, TabularDataset
with open("configs/binary_classsifier_simple_example.yaml") as stream:
config = yaml.safe_load(stream)
dataset = TabularDataset.from_config(config["dataset"] | {"label_columns": "source"})
trainer = SimpleTrainer.from_config(config["trainer"])
trainer.fit(dataset)
scores = trainer.evaluate(dataset)
trainer.save_snapshot("example-run")Trainer configuration uses dotted import paths for models, metrics, callbacks,
calibrators, optimizers, losses, and other pluggable pieces. For example,
model_type: sklearn.ensemble.RandomForestClassifier builds an sklearn random
forest, while model_type: skorch.NeuralNetClassifier builds a skorch-wrapped
torch network. Nested values of the form {"type": "package.Object"} are
resolved to live Python objects, which is useful for torch modules and losses in
YAML.
SimpleTrainer is intended for estimators that can train on materialized
feature and target arrays. It supports sklearn-style estimators, skorch
estimators, optional sklearn calibration wrappers, task-aware metrics, snapshots,
and standalone model export.
EpochTrainer owns separate training, validation, and test dataset
configuration. It is the better fit for torch models that should train in
batches over multiple epochs, with skorch callbacks, checkpointing, early
stopping, learning-rate schedulers, metrics, snapshots, and model export.
TabularDataset treats each row in a directory of tabular files as one sample.
It currently supports registered tabular formats such as CSV and parquet through
PyArrow-backed handlers. Files are ordered consistently and rows can be indexed like
a torch dataset.
The dataset configuration names the data path, read options, file suffix, and target column or columns:
from GalaxySpectrumClassifier import TabularDataset
dataset = TabularDataset(
path="data/classification_v2",
dataformat="csv",
suffix=".csv",
label_columns="source",
)
features, target = dataset[0]Optional pre_filter and pre_transform hooks run once into an on-disk cache,
while transform prepares rows at retrieval time. These hooks can also be
configured with dotted import paths so they can live in YAML alongside the rest
of the experiment.
The trainers are designed to bridge sklearn-style and torch-style workflows.
Use sklearn estimators directly with SimpleTrainer when the model consumes
full arrays. Use skorch estimators with SimpleTrainer when a torch module can
still be trained through the sklearn estimator interface.
For longer neural-network training runs, use EpochTrainer. It builds the
appropriate skorch wrapper for the configured task:
NeuralNetBinaryClassifierfor binary classification.NeuralNetClassifierfor multiclass classification.NeuralNetRegressorfor regression.
This keeps torch modules usable in sklearn-like workflows while still allowing batch loading, callbacks, checkpointing, and metrics during epoch-based training.
This repository was set up using the SSC Cookiecutter for Python Packages.