Regression
Linear regression
Predict from training data set the price of the houses.
X (sizes in feet^2) / Y (price ($) in 1000's
\[
X = \begin{bmatrix}
2104 \\
1416 \\
1534 \\
852 \\
...
\end{bmatrix} \; \;
Y = \begin{bmatrix}
460 \\
232 \\
315 \\
178 \\
...
\end{bmatrix}
\]
Hypothesis
We are assuming that the hypothesis function is a straight line.
\(
h_\theta(x) = \theta_{0} + \theta_{1}x
\)
We will be trying out various values of \(\theta_{0}\) and \(\theta_{1}\).
The idea is to choose \(\theta_{0}\) and \(\theta_{1}\) so that h(x) is close to y for training examples.
Cost function
Cost function is measuring the accuracy of hypothesis function. The algorithm is trying diffent \(\theta_0\), \(\theta_1\), for which cost function is minimum. For visualization we can simplify things, by choosing \(\theta_{0} = 0\). There are other cost functions that will work preaty wel. But this "square error cost function" is the most commonly used. This is practically an average of all the \(h_{\theta}(x) - y\) results.
\(
J(\theta_{0}, \theta_{1}) = 1/2m * \sum_{i=0}^m (h_{\theta}(x^{(i)}) - y^{(i}))^2
\)
Multivariate
Linear regression with multiple variables. \(\theta_{0}\) as the basic price of a house \(\theta_{1}\) as the price per square meter \(\theta_{2}\) as the price per floor, ... The multiple variables form of hypothesis function:
\(
h_{\theta}(x) = \theta_{0} + \theta_{1}x + ... + \theta_{n}x
\)
Matrix representation, if we consier \(x_{0} = 1\)
\(
h_\theta(x) = [\theta_0 \theta_0 ... \theta_n]
\begin{bmatrix}
x_0 \\ x_1 \\ . \\ x_n
\end{bmatrix}
\)
Representation
- \(x_j^{(i)}\) = value of feature j in the \(i^{th}\) training example - m = the number of training examples (matrix rows) - n = the number of featuresTranspose
The transpose matrix of vector \theta is rotating in clockwise direction.\(
\theta^T =
\begin{bmatrix}
\theta_{0} \\ \theta_{1} \\ . \\ \theta_{n}
\end{bmatrix}
\)
Compact
If we consider \(x_0 = 1\) our hypothesis function could be represented as:\(
h_\theta(x) = \theta^Tx
\)
Cost function
Cost function is measuring the accuracy of hypothesis function.
\(
J(\theta_{0}, \theta_{1}, ...) = 1/2m * \sum_{i=0}^m (h_{\theta}(x^{(i)}) - y^{(i}))^2
\)
Last update: 243 days ago