December 2018
Beginner to intermediate
684 pages
21h 9m
English
The sklearn library includes an SGDRegressor model in its linear_models module. To learn the parameters for the same model using this method, we need to first standardize the data because the gradient is sensitive to the scale. We use StandardScaler() for this purpose that computes the mean and the standard deviation for each input variable during the fit step, and then subtracts the mean and divides by the standard deviation during the transform step that we can conveniently conduct in a single fit_transform() command:
scaler = StandardScaler()X_ = scaler.fit_transform(X)
Then we instantiate the SGDRegressor using the default values except for a random_state setting to facilitate replication:
sgd ...