Machine Learning Andrew Ng -4. Linear Regression with multiple variables

4.1 Multiple features (多特征量)

Multiple features (variables)

Size (x1)(x_1) Number of bedrooms(x2)(x_2) Number of floors(x3)(x_3) Age of homes(x4)(x_4) Price(y)(y)
2104 5 1 45 460
1416 3 2 40 232
1534 3 2 30 315
852 2 1 36 178

Notation :

  • nn = number of features
  • x(i)x^{(i)}= input (features) of ithi^{th} training example
  • xj(i)x_j^{(i)} = value of feature jj in ithi^{th} training example

Hypothesis :

previously : hθ(x)=θ0+θ1xh_{\theta}(x) = \theta_0 + \theta_1x

now : hθ(x)=θ0+θ1x1+θ2x2+θ3x3+θ4x4h_{\theta}(x) = \theta_0+\theta_1x_1+\theta_2x_2+\theta_3x_3+\theta_4x_4

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

Multivariate linear regression 多元线性回归

4.2 Gradient descent for multiple variables

How to fit the parameters of that hypothesis ? How to use gradient descent for linear regression with multiple features ?

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

4.3 Gradient descent in practice I : Feature Scaling(特征缩放)

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

Feature Scaling : Get every feature into approximately a 1xi1-1 \leqslant x_i\leqslant 1 range.

Mean normalization (均值归一化) :

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

4.4 Gradient descent in practice II : Learning rate

Machine Learning Andrew Ng -4. Linear Regression with multiple variables
Machine Learning Andrew Ng -4. Linear Regression with multiple variables
Machine Learning Andrew Ng -4. Linear Regression with multiple variables

4.5 Features and polynomial regression (特征和多项式回归)

Choosing feature

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

The price could be a quadratic function (二次函数), or a cubic function (三次函数)

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

now feature scaling is more important

Machine Learning Andrew Ng -4. Linear Regression with multiple variables
How to choose features ? Discuss later…

4.6 Normal equation (正规方程)

Normal equation : Method to solve for θ\theta analytically.

One step, you get to the optimal value right there.

Machine Learning Andrew Ng -4. Linear Regression with multiple variables
Machine Learning Andrew Ng -4. Linear Regression with multiple variables
Machine Learning Andrew Ng -4. Linear Regression with multiple variables

这里X矩阵上下标大概率写错了

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

Feature Scaling is no need

When choose gradient descent when choose normal equation ?

Machine Learning Andrew Ng -4. Linear Regression with multiple variables

4.7 Normal equation and non-invertibility

Machine Learning Andrew Ng -4. Linear Regression with multiple variables
Machine Learning Andrew Ng -4. Linear Regression with multiple variables