Programming Exercise 2: Logistic Regression
Machine Learning October 30, 2011
In this exercise, you will implement logistic regression and apply it to two diﬀerent datasets. Before starting on the programming exercise, we strongly recommend watching the video lectures and completing the review questions for the associated topics. To get started with the exercise, you will need to download the starter code and unzip its contents to the directory where you wish to complete the exercise. If needed, use the cd command in Octave to change to this directory before starting this exercise. You can also ﬁnd instructions for installing Octave on the “Octave Installation” page on the course website.
Files included in this exercise
ex2.m - Octave script that will help step you through the exercise ex2 reg.m - Octave script for the later parts of the exercise ex2data1.txt - Training set for the ﬁrst half of the exercise ex2data2.txt - Training set for the second half of the exercise submit.m - Submission script that sends your solutions to our servers mapFeature.m - Function to generate polynomial features plotDecisionBounday.m - Function to plot classiﬁer’s decision boundary [ ] plotData.m - Function to plot 2D classiﬁcation data [ ] sigmoid.m - Sigmoid Function [ ] costFunction.m - Logistic Regression Cost Function [ ] predict.m - Logistic Regression Prediction Function [ ] costFunctionReg.m - Regularized Logistic Regression Cost indicates ﬁles you will need to complete 1
Throughout the exercise, you will be using the scripts ex2.m and ex2 reg.m. These scripts set up the dataset for the problems and make calls to functions that you will write. You do not need to modify either of them. You are only required to modify functions in other ﬁles, by following the instructions in this assignment.
Where to get help
The exercises in this course use Octave,1 a high-level programming language well-suited for numerical computations. If you do not have Octave installed, please refer to the installation instructons at the “Octave Installation” page http://www.ml-class.org/course/resources/index?page=octave-install on the course website. At the Octave command line, typing help followed by a function name displays documentation for a built-in function. For example, help plot will bring up help information for plotting. Further documentation for Octave functions can be found at the Octave documentation pages. We also strongly encourage using the online Q&A Forum to discuss exercises with other students. However, do not look at any source code written by others or share your source code with others. If you run into network errors using the submit script, you can also use an online form for submitting your solutions. To use this alternative submission interface, run the submitWeb script to generate a submission ﬁle (e.g., submit ex2 part1.txt). You can then submit this ﬁle through the web submission form in the programming exercises page (go to the programming exercises page, then select the exercise you are submitting for). If you are having no problems submitting through the standard submission system using the submit script, you do not need to use this alternative submission interface.
In this part of the exercise, you will build a logistic regression model to predict whether a student gets admitted into a university. Octave is a free alternative to MATLAB. For the programming exercises, you are free to use either Octave or MATLAB. 1
Suppose that you are the administrator of a university department and you want to determine each applicant’s chance of admission based on their results on two exams. You have historical data from previous applicants that you can use as a training set for logistic regression. For each training example, you have the applicant’s scores on two exams and the admissions decision. Your task is to build a classiﬁcation model that estimates an applicant’s...
Please join StudyMode to read the full document