Been testing some basic code and trying to plot its loss function but get some errors. Need your help to move on. Here is the code:
using Flux
actual(x) = 2x + 3
x_train, x_test = hcat(0:5…), hcat(6:10…)
y_train, y_test = actual.(x_train), actual.(x_test)
model = Dense(1, 1)
predict = model
loss(x, y) = Flux.Losses.mse(predict(x), y)
opt = Descent()
data = [(x_train, y_train)]
parameters = Flux.params(predict)
Flux.train!(loss, parameters, data, opt)’
I get error on this last block of code
epochs = Int64
loss_on_train = Float32
loss_on_test = Float32
for epoch in 1:2000
Flux.train!(loss, parameters,data, opt)
# we record our training loss
push!(epochs, epoch)
push!(loss_on_test, loss(x_test, y_test).data)
push!(loss_on_train, loss(x_train, y_train).data)
end
using Plots
plot(epochs, loss_on_train, lab=“Training”, c=:black, lw=2);
plot!(epochs, loss_on_test, lab=“Testing”, c=:teal, ls=:dot);
yaxis!(“Loss”, :log);
xaxis!(“Training epoch”)
Here is the error:
type Float32 has no field data