using Pandas using Plots using Flux df = read_csv("airline-passengers.csv") # Get the two datasets of one point time-series # The train data and target train = values(df[1:length(df)-2].Passengers) target_train = values(df[2:length(df)].Passengers) Plots.plot(train) plot!(target_train) train = [[convert(Float32, train[i])] for i = 1:length(train)] train = reshape(train, (length(train), 1)) target_train = reshape(target_train, (length(target_train), 1)) target_train = [convert(Float32, target_train[i]) for i = 1:length(target_train)] # Model and Training model = Chain(RNN(1,4), Dense(4, 1, x->x)) loss(x, y) = sum(abs2.(eval_model(x) .- y)) function eval_model(x) #@show x out = model.(x) @show out #Flux.reset!(model) out = [out[i] for i=1:length(out)] end ps = Flux.params(model); opt = Flux.ADAM(0.01) epochs = 100 for epoch in 1:epochs @show epoch #loss(train, target_train) gs = Flux.gradient(ps) do @show loss(train, target_train) end Flux.Optimise.update!(opt, ps, gs) end out = model.(train) out = [out[i] for i=1:length(out)] Plots.plot(out)
Does anybody see any problem?