Applied Machine Learning in Matlab 3
当前位置:以往案例 > >Applied Machine Learning in Matlab 3
2023-01-04

Programming project 3

In this programming project, we will implement logistic regression. Since logistic regression has many similarities with linear regression, you will reuse most of the code from your assignment 2 solutions. Those reused code are given among the assignment files.

Before you start programming:

●  Make sure that you have Octave on your system.
●  Download and extract the assignment zip from Gradescope. Make sure you have the files “data1.txt”, “data2.txt”, “run.m” and several other “.m” files in the assignment directory. Do not change the contents of those existing files unless you are instructed to do so.
●  Open a terminal and navigate to the assignment directory using the “cd” command.
●  Using the same terminal, run Octave with the “octave” command.
●  The “run” script is ready to use the code that you will implement in this assignment.

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.

Load data into a Design Matrix and an output vector

You will use the same loadData function that you implemented for the previous assignment. Our training dataset in “data.txt” has the output values of training examples at its last column as usual, but this time those output values are binary, i.e. they are either 0 or 1, indicating the class of the training example. The “run” script will plot the data on the screen.

Implement the sigmoid function

Logistic regression applies the sigmoid function over the weighted sum of features. Implement the function “g”, which applies the sigmoid transformation to the given parameter.

xx
To calculate e , you can use the built-in function “exp” (exp(x) = e ). For the division operator,

make sure you use a dot division (“./”). This will allow x to be a vector or a matrix.

Implement the hypothesis function

We will implement a function that calculates h


在线提交订单