Job 1 Linear Regression

Programming Assignment 1: Linear Regression

Introduction:

         In this section exercise, you will learn how to implement linear regression and its data processing. Before the start of this section programming practice, we strongly recommend watching the video lectures and review of related topics.

         To practice before the start, you need to download the initial code and extract it to a directory of links you want to go to completion. If necessary, you can use octave / matlab in cd command to change the directory. You can also find instructions for installing Octave / Matlab in "Environment setup instructions" course website.

This exercise included files:

ex1.m - Octave / MATLAB script to guide you through the exercises

ex1 multi.m - octave exercise later in / matlab script

ex1data1.txt - linear regression data set

ex1data2.txt - multiple linear regression data set

submit.m - will be sent to our server solutions submitted script

[*] WarmUpExercise.m - simple example function octave / matlab in

[*] PlotData.m - Data Display Function

[*] ComputeCost.m - calculating the linear regression of the cost function

[*] GradientDescent.m - run a gradient decreasing function

[+] ComputeCostMulti.m - multiple linear regression cost function

[+] GradientDescentMulti.m - multivariate gradient descent

[+] FeatureNormalize.m - normalization feature function

[+] NormalEqn.m - Function Calculation Equation

* Indicates that the file you want to accomplish

† denotes an optional practice

Throughout the exercise, you will use a script ex1.m and ex1 multi.m. These scripts set up data sets and functions you will be called to question. You just modify other file functions Follow the instructions in this task. For this exercise program, you only need to complete the first part of the exercise, namely to achieve a variable linear regression. The second part is optional, includes multivariate linear regression.

Where to get help

To the west of the course it is ideal for use Octavel1 or Matalab high-level language for numerical calculation. If you do not Octave or Matlab, please refer to the installation instructions Course Website "Environment setup instructions" in the. In octave / matlab command line, type help and followed by the function name, document built-in functions will be displayed. For example, "Help Drawing" in which information for drawing. More information on can be found on the Octave Octave profile page for more information on it can be found on MATLAB in the MATLAB data page. We also strongly encourage the use of the Internet and discussing exercises with other students. However, do not see any source code written by others, and do not share your source code with other people.

1, a simple octave / Matlab function

。。。

2, a linear regression

         In the exercise part of this section, you will use a linear regression to predict the performance of fast cars. Suppose you are CEO of a fast food chain, it is considering opening new stores in different cities. The chain has fast cars in each city, and you have income and population data from the various cities.

         You want to use this data to help you choose the next to expand the city. Ex1data1.txt file containing the data set of linear regression problem. The first column is the population of a city, and the second column is the city vans benefits. Negative values ​​indicate losses, ex1.m script already set to load this data for you.

2.1 The drawing data

         Before starting any task, when the data visualization is very useful. For this data set, a scatter plot may be used to visualize data, because it has only two attributes drawable (Profit and population). (Many of the problems you encounter in real life are not multi-dimensional drawing on a two dimensional map.

Gradient descent 2.2

In this section, you will use the parameter theta solving linear regression gradient descent

2.2.1 update equation

Linear regression goal is to minimize the cost function

 

 

 Suppose H [Theta] (X) has given the following form:

hΘ(x) = ΘTx=Θ0+Θ1x1

 Recall that the model parameters θj value. You'll adjust these values ​​to minimize the cost function J (Θ). An algorithm is a batch gradient descent method (batch gradient descent algorithm.). Each iteration will be updated

(For all j, while updating θj)

 

 

Every step gradient descent, you will be close to the optimal parameters θj value (lowest cost cost J (Θ)).

Implementation Note: We will most row of each sample data stored by Octave / MATLAB in the X matrix. Taking into account the intercept (θ0), we added an additional matrix X and a are set to 1. This allows us to θ0 as another "feature."

 

2.2.2 achieve

  In ex1.m, we have established a data linear regression. In the following lines, we add another dimension in the data to fit θ0 intercept. We initialization parameters from 0 to 0.01 learning efficiency.

 

Guess you like

Origin www.cnblogs.com/weststar/p/11613627.html