How to train/predict a very simple feed-forward neural network in Flux?

I’m sorry that your experience has been less than ideal, but I found Flux’s documentation a really good starting point. The training section, for example, details how to set up a model.

Here’s how your toy example could be implemented:

using Flux

xtrain     = [0.1 0.2; 0.3 0.5; 0.4 0.1; 0.5 0.4; 0.7 0.9; 0.2 0.1]
ytrain     = [0.3; 0.8; 0.5; 0.9; 1.6; 0.3]
xtest      = [0.5 0.6; 0.14 0.2; 0.3 0.7]
ytest      = [1.1; 0.36; 1.0]

model = Dense(2, 1) # Use Chain if you want to stack layers

loss(x, y) = Flux.mse(model(x), y)
ps = params(model)
dataset = [(xtrain', ytrain')] # Use DataLoader for easy minibatching
opt = ADAGrad()

Flux.@epochs 100 Flux.train!(loss, ps, dataset, opt) 

The train loop also takes an additional keyword argument cb for callbacks. For instance, if you want to see how the loss improves each epoch:

cb = () -> println(loss(xtrain', ytrain'))
Flux.@epochs 100 Flux.train!(loss, ps, dataset, opt, cb = cb)
2 Likes