Using SGD for regression
In this recipe, we'll get our first taste of stochastic gradient descent. We'll use it for regression here.
Getting ready
SGD is often an unsung hero in machine learning. Underneath many algorithms, there is SGD doing the work. It's popular due to its simplicity and speed—these are both very good things to have when dealing with a lot of data. The other nice thing about SGD is that while it's at the core of many machine learning algorithms computationally, it does so because it easily describes the process. At the end of the day, we apply some transformation on the data, and then we fit our data to the model with a loss function.
How to do it…
- If SGD is good on large datasets, we should probably test it on a fairly large dataset:
from sklearn.datasets import make_regression X, y = make_regression(int(1e6)) #1,000,000 rows
It's probably worth gaining some intuition about the composition and size of the object. Thankfully, we're dealing with NumPy arrays, so we can just...