Skip to main content

Experiment Tracking

Track ML experiments with parameters, metrics, artifacts, and automatic system information capture.

Overview

Strongly's experiment tracking automatically captures:

  • Hyperparameters and configuration
  • Training metrics over time
  • Artifacts (files, plots, reports)
  • Git commit information
  • System information (Python version, packages, hardware)

Basic Usage

import strongly_python as strongly

# Set experiment name (optional - auto-generated if not set)
strongly.set_experiment("my-classification-experiment")

# Start a run with context manager
with strongly.start_run(run_name="random-forest-baseline"):
# Log hyperparameters
strongly.log_params({
"n_estimators": 100,
"max_depth": 10,
"min_samples_split": 2
})

# Log metrics during training
for epoch in range(10):
strongly.log_metrics({
"train_loss": 0.5,
"val_loss": 0.6,
"accuracy": 0.85
}, step=epoch)

# Log final metrics
strongly.log_metrics({
"final_accuracy": 0.92,
"f1_score": 0.89
})

# Add tags for organization
strongly.set_tags(["baseline", "sklearn", "classification"])

Logging Parameters

Parameters are logged once and represent configuration values.

# Log single parameter
strongly.log_param("learning_rate", 0.01)

# Log multiple parameters
strongly.log_params({
"n_estimators": 100,
"max_depth": 10,
"random_state": 42
})

Logging Metrics

Metrics can be logged with optional step values for tracking over time.

# Log single metric
strongly.log_metric("accuracy", 0.95)

# Log metric with step (for training curves)
strongly.log_metric("loss", 0.5, step=0)
strongly.log_metric("loss", 0.3, step=1)
strongly.log_metric("loss", 0.1, step=2)

# Log multiple metrics at once
strongly.log_metrics({
"train_loss": 0.1,
"val_loss": 0.15,
"accuracy": 0.95
}, step=epoch)

Logging Artifacts

Artifacts are files associated with your run (models, plots, reports, etc.).

# Log a single file
strongly.log_artifact("model_report.txt")

# Log a directory of files
strongly.log_artifact("plots/")

# Create and log a file
with open("results.txt", "w") as f:
f.write("Model accuracy: 0.95\n")
strongly.log_artifact("results.txt")

Logging Models

Log trained models with automatic framework detection.

from sklearn.ensemble import RandomForestClassifier

# Train a model
model = RandomForestClassifier()
model.fit(X_train, y_train)

# Log the model
strongly.log_model(model, "random_forest_model")

Supported frameworks:

  • scikit-learn
  • PyTorch
  • TensorFlow/Keras
  • XGBoost
  • LightGBM
  • CatBoost

Tags

Tags help organize and filter experiments.

# Add single tag
strongly.set_tag("baseline")

# Add multiple tags
strongly.set_tags(["production", "sklearn", "v2"])

Run Management

# Start run with context manager (recommended)
with strongly.start_run(run_name="my-run"):
# ... training code ...
pass # Run automatically ends

# Manual run management
strongly.start_run(run_name="my-run")
# ... training code ...
strongly.end_run()

# Get current run info
run = strongly.active_run()
print(f"Run ID: {run.run_id}")
print(f"Run Name: {run.run_name}")

Autolog

Automatically capture training details from ML frameworks.

# Enable for all supported frameworks
strongly.autolog()

# Enable for specific frameworks
strongly.autolog(include=["sklearn", "xgboost"])

# Disable autolog
strongly.autolog(disable=True)

What Autolog Captures

FrameworkParametersMetricsModels
scikit-learnEstimator paramsTraining scoreTrained model
PyTorchLearning rate, optimizerLoss per epochState dict
TensorFlow/KerasLayer config, optimizerEpoch metricsSavedModel
XGBoostBooster paramsEval metricsBooster
LightGBMParamsIteration metricsModel
CatBoostParamsBest scoresModel

Complete Example

import strongly_python as strongly
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, f1_score

# Set experiment
strongly.set_experiment("customer-churn-prediction")

# Load and split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

with strongly.start_run(run_name="rf-baseline"):
# Log hyperparameters
params = {
"n_estimators": 100,
"max_depth": 10,
"min_samples_split": 2,
"random_state": 42
}
strongly.log_params(params)

# Train model
model = RandomForestClassifier(**params)
model.fit(X_train, y_train)

# Evaluate
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)

# Log metrics
strongly.log_metrics({
"accuracy": accuracy,
"f1_score": f1
})

# Log model
strongly.log_model(model, "churn_classifier")

# Add tags
strongly.set_tags(["baseline", "random-forest"])

print(f"Run ID: {strongly.active_run().run_id}")

API Reference

Experiment Management

FunctionDescription
set_experiment(name)Set or create experiment
start_run(run_name)Start a new run
end_run()End current run
active_run()Get current run info

Logging

FunctionDescription
log_param(key, value)Log single parameter
log_params(dict)Log multiple parameters
log_metric(key, value, step)Log single metric
log_metrics(dict, step)Log multiple metrics
set_tag(tag)Add single tag
set_tags(list)Add multiple tags
log_artifact(path)Log file artifact
log_model(model, name)Log model
autolog()Enable automatic logging