Software Toolkit#
The examples in this book use a small collection of Python packages. You do not need to master them before starting. It is enough to know which job each package performs and to recognize the main data structures as they move through a modeling workflow. However, reading their documentation will be beneficial in the long run.
Jupyter notebooks and Google Colab#
A Jupyter notebook mixes explanatory text, executable Python, figures, and saved results. Run cells from top to bottom because later cells usually depend on variables created earlier. Google Colab runs the same kind of notebook in a temporary cloud environment, so downloaded data and installed extras may need to be recreated when the runtime restarts.
Package map#
Package |
Typical import |
Role in this book |
|---|---|---|
|
Numerical arrays and vectorized calculations |
|
|
Dataframes, timestamps, and tabular data cleaning |
|
|
Scientific Figures |
|
|
Data splits, preprocessing, baselines, metrics, and diagnostic displays |
|
|
Canonical neural betwork models, and automatic differentiation |
|
|
A higher-level model API using the same PyTorch backend |
|
|
Gradient-boosted tree models for tabular and flattened inputs |
|
|
Validation-based hyperparameter searches |
|
|
Model-behavior diagnostics that require careful interpretation |
Other useful packages#
The following packages are also particularly useful to use in future exampels or experimentation.
Package |
Typical import |
When it may be useful |
|---|---|---|
|
Time-series distances, clustering, classification, and related learning tools |
|
|
A unified interface for forecasting, classification, transformation, and other time-series tasks |
|
|
Higher-level statistical graphics built on Matplotlib |
|
|
Efficient gradient-boosted tree models, especially for tabular data, similar to XGBoost |
|
|
Resampling methods, pipelines, and metrics for imbalanced classification problems |
|
|
Statistical models, hypothesis tests, classical time-series methods, and detailed inference summaries |
Three common data representations#
A pandas.DataFrame keeps column names and timestamps, which is helpful while
auditing and cleaning scientific tables. NumPy arrays provide compact
numerical matrices for preprocessing and many classical models.
import pandas as pd
import torch
frame = pd.DataFrame({"speed": [400.0, 525.0], "bz": [-2.0, 4.0]})
array = frame[["speed", "bz"]].to_numpy(dtype="float32")
tensor = torch.from_numpy(array)
PyTorch is the canonical path#
PyTorch exposes the important steps explicitly: create tensors, define a
model, calculate a loss, backpropagate, update parameters, and evaluate with
gradients disabled. Keras 3 offers a shorter compile() and fit() workflow while still using PyTorch underneath. The backend must be selected before importing Keras:
import os
os.environ["KERAS_BACKEND"] = "torch"
import keras
assert keras.backend.backend() == "torch"
The Keras notebooks are alternative implementations, not a second modeling method. Their data boundaries, architecture intent, metrics, and scientific interpretation are almost identical to the PyTorch workflow.