Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python code. Any way I can better my code. Problem #4 Find the best ft by minimizing the objoctive function (m)-Xm -yll using gradient descent

Python code. Any way I can better my code. image text in transcribed
Problem #4 Find the best ft by minimizing the objoctive function (m)-Xm -yll using gradient descent Follow these steps a Define the function f(m) b. Define the vector function Vf(m) C Wrte a short sagt that mglermonts gradont descent Use step sue ". IO-, and toleranco -10-8 Koep track of te number of iterations d Plot the data again and the solution yD mx+ b on the same figure Make sure you include time commands to find the CPU time it took to find the solution this way 59]: def fobj(X,m,y): return 0.5"np. linale.norm(.dot (m)-ydata)..2 def gradf (X,m, ydata): return ((XT. dot (x). dot (m)-XT.dot (ydata))) t start_DG time.time() Tau- 8.01 delta- 8.8000801 deltagrad-8.0086088960001 k-8 kmax: 100e mk np.zeros(X. shape[1]) fk fobj(x, mk, ydata) gradk- gradf(x, mk, data) while fk delta and k deltagrad: nk mk- Tau gradk fk- fobj(X, mk, ydata) gradk- gradf(X, mk, ydata) t DG- time.time()-t start DG ValueErrorTraceback (nost recent call last) cipython-input-59-532b3ddfbe7b> in cmodule>) 13 fk- fobj(x, mk, ydata) 14 gradk gradf(x, mk, data) .15 while fk > delta andkkmax and gradk > deltagrad: 16 ak ak- Tau gradk 17 fk- fobj(X,-, ydata) ValueError: The truth value of an array with more than one element is anbiguous. Use a. any() or a.all

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions