Elastic net regression is a type of regression that combines lasso regression with ridge regression by adding a L1 and L2 regularization term to the loss
function.
Implementing elastic net regression should be straightforward after the previous two recipes, so we will implement this in multiple linear regression on the iris dataset, instead of sticking to the two-dimensional data as before. We will use pedal length, pedal width, and sepal width to predict sepal length.
First we load the necessary libraries and initialize a graph, as follows:
import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from sklearn import datasets sess = tf.Session()
Now we will load the data. This time, each element of
x
data will be a list of three values instead of one. Use the following code:iris = datasets.load_iris() x_vals = np.array([[x[1], x[2], x[3]] for x in iris.data]) y_vals = np.array([y[0] for y in iris.data])
Next we declare...