Machine Learning

Explicit-parameter neural networks (functional style, great for SciML):

34.1 Flux.jl

using Flux

model = Chain(
    Dense(4 => 16, relu),
    Dense(16 => 3),
    softmax
)
x = rand(Float32, 4, 100)                         # features × samples
y = Flux.onehotbatch(rand(1:3, 100), 1:3)
loss(m, x, y) = Flux.crossentropy(m(x), y)
opt_state = Flux.setup(Adam(0.01), model)
data = Flux.DataLoader((x, y), batchsize=16, shuffle=true)
for epoch in 1:50
    Flux.train!(loss, model, data, opt_state)
end
accuracy = mean(Flux.onecold(model(x)) .== Flux.onecold(y))
model_gpu = model |> gpu                          # move to GPU

34.2 Lux.jl

Explicit-parameter neural networks (functional style, great for SciML):

using Lux, Random, Optimisers, Zygote
rng = Random.default_rng()
model = Lux.Chain(Lux.Dense(2 => 8, tanh), Lux.Dense(8 => 1))
ps, st = Lux.setup(rng, model)
y, st = model(rand(Float32, 2, 10), ps, st)

34.3 MLJ.jl — classical ML framework

200+ models (XGBoost, LightGBM, scikit-learn wrappers, GLMs, clustering), pipelines, tuning, and model composition.

using MLJ
X, y = @load_iris
Tree = @load DecisionTreeClassifier pkg=DecisionTree
mach = machine(Tree(max_depth=3), X, y)
evaluate!(mach, resampling=CV(nfolds=5), measure=[accuracy, log_loss])
fit!(mach); predict_mode(mach, X)

34.4 Other ML/AI tools

MLUtils.jl, Metalhead.jl (vision models), Transformers.jl, ONNX.jl, Clustering.jl, MultivariateStats.jl (PCA, LDA), GLM.jl, Reactant.jl (XLA compilation), ReinforcementLearning.jl, POMDPs.jl (decision making under uncertainty).