Software Toolkit#
The examples use a small set of Python packages. You do not need to know them before starting; it is enough to know what each one is for and to recognize the main data structures as they pass through a workflow. Their documentation, linked below, is worth reading as you go further.
Jupyter notebooks and Google Colab#
A Jupyter notebook mixes text, executable Python, figures, and saved results. Run the cells from top to bottom, because later cells use variables created by earlier ones. Google Colab runs the same notebooks in a temporary cloud environment; downloaded data and installed packages disappear when the runtime restarts, and the notebooks fetch them again.
Packages used in the book#
Package |
Typical import |
Role in this book |
|---|---|---|
|
Arrays and vectorized arithmetic |
|
|
Tables with named columns and timestamps |
|
|
Figures |
|
|
Data splits, preprocessing, and metrics |
|
|
Neural networks and automatic differentiation |
|
|
A higher-level neural-network API, run here on PyTorch |
|
|
Gradient-boosted trees |
|
|
Hyperparameter search |
|
|
Attributing a model’s predictions to its inputs |
Other useful packages#
These are not used in the notebooks yet but are worth knowing.
Package |
Typical import |
Use |
|---|---|---|
|
Regression with full inference, hypothesis tests, and classical time-series models |
|
|
One interface for time-series forecasting, classification, and transformation |
|
|
Time-series distances, clustering, and classification |
|
|
Resampling and metrics for rare-class problems |
|
|
Gradient-boosted trees, often faster than XGBoost on large tables |
|
|
Statistical graphics built on Matplotlib |
|
|
Solar data search, download, and coordinate handling |
|
|
Programmatic access to NASA CDAWeb, including OMNI |
Three data representations#
A pandas DataFrame keeps column names and timestamps, which helps while
inspecting and cleaning scientific tables. A NumPy array is a plain numerical
matrix, the input most preprocessing and classical models expect. A PyTorch
tensor is the array a neural network consumes; it can live on a GPU and
record the operations needed for gradients. Converting between them is one
line each:
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 and Keras#
PyTorch makes each step of training explicit: build tensors, define a model,
compute a loss, backpropagate, update the weights, and evaluate with
gradients switched off. Keras 3 wraps the same steps in compile() and
fit(), and in this book it runs on the PyTorch backend. The backend must be
chosen before Keras is imported:
import os
os.environ["KERAS_BACKEND"] = "torch"
import keras
assert keras.backend.backend() == "torch"
The Keras notebooks use the same data, split, architecture, and metrics as the PyTorch notebooks, so their results should agree closely. Small differences come from the frameworks’ different default weight initializations and random-number streams.