@@ -15,6 +15,10 @@ Regression and time-series prediction
15
15
- 90 min teaching
16
16
- 60 min exercises
17
17
18
+ .. callout ::
19
+
20
+ The code in this lession is written for Julia v1.11.2.
21
+
18
22
Linear regression with synthetic data
19
23
-------------------------------------
20
24
@@ -545,7 +549,7 @@ The mean pressure data field seems to contain some unreasonably large values. Le
545
549
546
550
using DataFrames, CSV, Plots, Statistics
547
551
548
- # data_path = "C:/Users/davidek/julia_kurser/DailyDelhiClimateTrain.csv"
552
+ # data_path = "C:/Users/davidek/julia_kurser/2025-02/ DailyDelhiClimateTrain.csv"
549
553
# full path to data files
550
554
# uploaded in julia-for-hpda/content/data
551
555
df_train = CSV.read(data_path, DataFrame)
@@ -602,7 +606,7 @@ Background on neural networks can be found here :download:`download slides </sli
602
606
using MLJ: shuffle, partition
603
607
using Flux: train!
604
608
605
- # data_path = "C:/Users/davidek/julia_kurser/DailyDelhiClimateTrain.csv"
609
+ # data_path = "C:/Users/davidek/julia_kurser/2025-02/ DailyDelhiClimateTrain.csv"
606
610
df = CSV.read(data_path, DataFrame)
607
611
608
612
# clean up data, drop rows
@@ -660,12 +664,11 @@ Background on neural networks can be found here :download:`download slides </sli
660
664
Dense(10, 1, init=init, bias=true)
661
665
)
662
666
663
- loss(tX, ty) = Flux.Losses.mse(model(tX'), ty')
667
+ loss(model, tX, ty) = Flux.Losses.mse(model(tX'), ty')
664
668
665
669
data = [(X_train, y_train)]
666
670
667
- ps = Flux.params(model)
668
- opt = ADAM(0.01) # learning rate 0.01
671
+ opt_state = Flux.setup(Adam(0.01), model) # learning rate 0.01
669
672
670
673
train_loss = []
671
674
test_loss = []
@@ -675,7 +678,7 @@ Background on neural networks can be found here :download:`download slides </sli
675
678
# replace the rest of the code from here with snippet below
676
679
677
680
for epoch in 1:n_epochs
678
- train!(loss, ps , data, opt )
681
+ train!(loss, model , data, opt_state )
679
682
ltrain = sqrt(loss(X_train, y_train))
680
683
ltest = sqrt(loss(X_test, y_test))
681
684
push!(train_loss, ltrain)
0 commit comments