In [1]:
using HDF5

h5file = h5open("hw_data.h5", "r")
train_x = permutedims(read(h5file["train_x"]), [2, 1])
train_y = read(h5file["train_y"])
test_x = permutedims(read(h5file["test_x"]), [2, 1])
close(h5file)
In [2]:
println(size(train_x))
println(size(train_y))
println(size(test_x))
(400, 10)
(400,)
(11, 10)
In [3]:
using LinearAlgebra

# train ridge regression
l = 2.0
covMat = transpose(train_x) * train_x
w = inv(covMat + l * I) * transpose(train_x) * train_y
Out[3]:
10-element Array{Float64,1}:
  4.30423825813129
 -5.008792367538665
  2.624938181181084
  6.013863027850682
  5.968164428331132
  1.3081792077878174
 -2.0831802342952663
 -1.2838384771492386
 -5.729078879401287
  5.538474428488576 
In [4]:
# get predictions
test_y = test_x * w
test_y_round = map(x->UInt8(round(x)), test_y)
test_y_output = String(test_y_round)
Out[4]:
"hello world"
In [ ]: