Storing and Querying ML Results
Persisting model predictions, experiment logs, and feature data in relational databases.
Tracking ML Experiments
As you train models you produce dozens of runs with different settings and scores. Without tracking, you lose which configuration worked best.
A small experiments database records every run so you can query, compare, and reproduce the winner.
Designing an Experiments Table
A good schema captures the run identity, the model, key hyperparameters, the metric, and a timestamp. Store flexible hyperparameters as a JSON text column.
import sqlite3
conn = sqlite3.connect("experiments.db")
conn.execute("""
CREATE TABLE IF NOT EXISTS runs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
model TEXT NOT NULL,
params TEXT,
accuracy REAL,
f1 REAL,
created_at TEXT DEFAULT (datetime("now"))
)
""")
conn.commit()All lessons in this course
- SQLite with Python's sqlite3 Module
- Pandas and SQL Integration
- Storing and Querying ML Results
- Introduction to Vector Databases