ある都市の住宅価格を予測する例を見てみましょう。
機械学習の用語では、家に関する情報は特徴と呼ばれ、価格予測はラベルと呼ばれます。

複数の特徴があり、それらの特徴から価格を予測できるモデルを学習させたい場合です。 多変量線形回帰を使用することができます。 このモデルは、まだ売られていない家の価格を予測したい場合、それがいくらで売られるかに近い予測を与えることができるように、以下の訓練データセットでパラメータ(θ0からθn)を学習する必要があります。



Practical Ideas for making Gradient Descent work well
- Use feature scaling to help gradient descent converge faster. Get every feature between -1 and +1 range. It doesn’t have to be exactly in the -1 to +1 range but it should be close to that range.

2. In addition to dividing the feature by maximum value people sometimes use mean normalization.

3. If we plot the value of cost function after each iteration of gradient descent, we should see that it converges. Below is a graph that shows gradient descent is converging. The number of iterations that it can take for gradient descent to converge varies a lot.



Polynomial Regression
Let’s say we have a housing price data set that looks like below.

Then there are a few different models we might fit to this.
One thing we could do is fit a quadratic model. It doesn’t look like a straight line fits this data very well. But then we may decide that quadratic model doesn’t make sense because of a quadratic function, eventually this function comes back down and we don’t think housing prices should go down when the size goes up too high. So then maybe we might choose a different polynomial model and choose to use instead a cubic function, and where we have now a third-order term and we fit that where green line is a somewhat better fit to the data cause it doesn’t eventually come back down. これは多変量線形回帰の手法で行うことができます。
ここで注意すべき重要なことは、特徴のスケーリングです。
ここで注意すべき重要なことは、特徴量のスケーリングです。家のサイズが1から1000の範囲であれば、家のサイズの2乗は1から100万の範囲となり、3番目の特徴量x cubedは1から10の範囲となり、これら3つの特徴量は非常に異なる値の範囲を取るので、勾配降下の特徴量スケーリングを適用して同等の値の範囲にすることが重要です。
ここでの別の妥当な選択は、家の価格は、θ0 にサイズのθ1 倍を加え、さらにサイズの平方根のθ2 倍を加えたものであると言うことかもしれません。

乗根関数の形状への洞察を持つことにより、次のことを行います。 そして、データの形状を理解し、異なる特徴を選択することで、より良いモデルを得ることができる場合があります。
このようにさまざまな特徴を選択できるのに、どの特徴を使うかどうやって決めたらいいのか、少し困惑しているように思えます。
しかし、それまでは、使用する特徴の選択肢があること、そして、さまざまな特徴を設計することにより、データに直線を当てはめるだけでなく、より複雑な関数を当てはめることができることを知っておく必要があります。