This is a brief summary of ML course provided by Andrew Ng and Stanford in Coursera.
You can find the lecture video and additional materials in
https://www.coursera.org/learn/machine-learning/home/welcome
Coursera | Online Courses From Top Universities. Join for Free
1000+ courses from schools like Stanford and Yale - no application required. Build career skills in data science, computer science, business, and more.
www.coursera.org
Linear Regression that works with multiple variables, or with multiple features.
In the previous version, we had a single variable, for example, size of the house when predicting the price of the house.
Now we wish to include more features such as num of bedrooms, num of floors, age of home when predicting the price of the house. This will give more inofrmation with which to predict the price.
Size ($ft^2$) | Number of bedrooms | Number of floors | Age of home (years) | Price ($1000) |
2104 | 5 | 1 | 45 | 460 |
1416 | 3 | 2 | 40 | 232 |
1534 | 3 | 2 | 30 | 315 |
852 | 2 | 1 | 36 | 178 |
Quiz: In the training set above, what is $x_1^4$?
Answer: The size of the 4th home in the training set. (852)
We used to have a hypothesis with single features and the form should change as we shifted to the multivariate.
Previously: $h_{\theta}(x) = \theta_0 + \theta_1x$
Multivariated: $h_{\theta}(x) = \theta_0 + \theta_1 x_1 + \theta_2 x_2 + \theta_3 x_3 + \theta_4 x_4 $
For convenience of notation, define $x_0$ = 1.
e.g., $x_0^{(1)} = 1$
$x = \left[\begin{array} {rrr} x_0 \\ x_1 \\ x_2 \\ x_3 \\ ... \\ x_n \end{array}\right] \in R^{n+1} $ $\theta = \left[\begin{array} {rrr} \theta_0 \\ \theta_1 \\ \theta_2 \\ \theta_3 \\ ... \\ \theta_n \end{array}\right] \in R^{n+1} $
$h_{\theta}(x) = \theta_0 + \theta_1 x_1 + \theta_2 x_2 + \theta_3 x_3 + \theta_4 x_4 = \theta^T x$
$\left[\begin{array} {rrr} \theta_0 & \theta_1 & \theta_2 & \theta_3 & ... & \theta_n \end{array}\right]$ $\left[\begin{array} {rrr} x_0 \\ x_1 \\ x_2 \\ x_3 \\ ... \\ x_n \end{array}\right] $
Multivariate Linear Regression
: Multiple Features, multivariables with which to try to predict the value Y.
Lecturer's Note
Linear regression with multiple variables is also known as "multivariate linear regression".
We now introduce notation for equations where we can have any number of input variables.
$x_j^{i}$ = value of feature j in the ith training example
$x^{i}$ = the input (features) of the ith training example
m = the number of training examples
n = the number of features
The multivariable form of the hypothesis function accommodating these multiple features is as follows:
$h_{\theta}(x) = \theta_0 + \theta_1 x_1 + \theta_2 x_2 + \theta_3 x_3 + \theta_4 x_4 = \theta^T x$
In order to develop intuition about this function, we can think about $\theta_0$ as the basic price of a house, $\theta_1$ as the price per square meter, $\theta_2$ as the price per floor, etc. $x_1$ will be the number of square meters in the house, $x_2$ the number of floors, etc.
Using the definition of matrix multiplication, our multivariable hypothesis function can be concisely represented as:
$h_\theta(x) = \left[\begin{array} {rrr} \theta_0 & \theta_1 & \theta_2 & \theta_3 & ... & \theta_n \end{array}\right]$ $\left[\begin{array} {rrr} x_0 \\ x_1 \\ x_2 \\ x_3 \\ ... \\ x_n \end{array}\right] $
This is a vectorization of our hypothesis function for one training example; see the lessons on vectorization to learn more.
Remark: Note that for convenience reasons in this course we assume $x_0^{(i)} = 1 $ for (i∈1,…,m). This allows us to do matrix operations with theta and x. Hence making the two vectors '$\theta$' and $x^{(i)}$ match each other element-wise (that is, have the same number of elements: n+1).