Question: function update _ grads! ( lr::LinearRegression, learning _ rate::Float 6 4 , grads ) ## Here you will implement update _ grads, this function returns
function updategrads!lr::LinearRegression, learningrate::Float grads
## Here you will implement updategrads, this function returns nothing.
## Search for setfield! and getfield functions.
## x learningrategrads will happen here!!!
lrtheta learningrate grads # Update theta
lrbias learningrate grads # Update bias
return nothing
return nothing
end
function fit!lr::linearregression,
X::AbstractMatrix,
y::AbstractVector;
learningrate::Float
maxiter::Integer
lambda ::Float
progress Progressmaxiter, "Computing...",
for iter in :maxiter
# Forward pass
ypred lrX
# Compute Huber loss
loss huberlossypred, y
# Compute gradients using Zygote
grads Zygote.gradientlr huberlosslrX y lr
# Update gradients with regularization term
gradstuple gradslambda lrtheta grads
# Update model parameters
updategrads!lr learningrate, gradstuple
# Update progress bar
next!progress
end
return nothing
end
## Let's give a try!!!
lr linearregression
X randn
y randn
fit!lr X y; learningrate maxiter
ERROR: ArgumentError: broadcasting over dictionaries and NamedTuples is reserved
Stacktrace:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
