If your features for linear regression are in different ranges, the result produced can be skewed. For example, if one of the features is in the range of 1 to 10 and the other is in the range of 3,000 to 50,000, then the predicted model will be bad. In such cases, the features must be rescaled so that they belong to almost the same range—ideally between 0 and 1.
The common strategy to scale a feature is to find the average and the range, and then using the following formula, all the values are updated:
In the preceding formula, is the mean or average of the values of feature and is the range or the standard deviation. The following code snippet shows how you can perform a feature scaling using F#.
You can calculate the feature scaling features by hand like this and then update the predictor matrix manually.
After the scaling, the house details matrix looks like this:
These values of the scaled matrix are very close to each other and thus the linear model generated.