July 2018
Beginner to intermediate
406 pages
9h 55m
English
Using scikit-learn, we can easily visualize what happens as the value of the regularization parameter (alphas) changes. We will again use the Boston data, but now we will use the Lasso regression object:
las = Lasso() alphas = np.logspace(-5, 2, 1000) alphas, coefs, _= las.path(x, y, alphas=alphas)
For each value in alphas, the path method on the Lasso object returns the coefficients that solve the Lasso problem with that parameter value. Because the result changes smoothly with alpha, this can be computed very efficiently.
A typical way to visualize this path is to plot the value of the coefficients as alpha decreases. You can do so as follows:
fig,ax = plt.subplots() ax.plot(alphas, coefs.T) # Set log scale ...
Read now
Unlock full access