Implementing a gradient descent algo
当前位置:以往案例 > >Implementing a gradient descent algo
2023-01-04

Programming project 1

The purpose of this project is to make you familiar with the Octave environment and practice implementing basic functions. You will implement a gradient descent algorithm for linear regression with a single variable.

Before you start programming:
● Make sure that you have Octave on your system. If not, see https://www.gnu.org/software/octave/download to learn how you can install it.
● Download and extract the project zip from Gradescope. Make sure you have the files “data.txt” and “run.m” in the project directory.
● Open a terminal and navigate to the project directory using the “cd” command.
● Using the same terminal, run Octave with the “octave” command.
● The project includes creating multiple text files with “.m” extension. Make sure you
know how to create a text file.
● The “run” script is ready to use the code that you will implement in this project.
Simply run it by typing “run” on the Octave console. It will initially give errors, but those errors will get resolved as you add the required functions. This script will also test your functions on some preset values and will print the expected and calculated values. If those values are significantly different, then please go back to your implementation and fix the error.
● Do not change the contents of those existing files unless you are instructed to do so.

Implement a function to load data into two vectors
We will implement a function that reads the input file “data.txt” (which has our training examples), and gives us a vector for x values and another vector for the y values. The name of the function will be “loadData” and it will be implemented in a file named “loadData.m” (this is also true for every other function: the function name has to match the file name, except the “.m” extension). 

The function should first read the data into a matrix using the “load” function. This will give us a matrix of 100 x 2. Then, it should split this matrix into two column vectors. 

Write a data plot function
The function “plotData” should take two vectors and their axis labels, and plot it on the screen. The “run.m” script calls this function as “plotData(x, y, ‘x’, ‘y’)”. The output should be similar to the plot below.
 
  Implement the hypothesis function
We will implement a function that calculates h

在线提交订单