Optimization with an example

Let's take an example of linear regression, where we try to find the best fit for a straight line through a number of data points by minimizing the squares of the distance from the line to each data point. This is why we call it least squares regression. Essentially, we are formulating the problem as an optimization problem, where we are trying to minimize a loss function.

Let's set up input data and look at the scatter plot:

# input dataxData = np.arange(100, step=.1)yData = xData + 20 * np.sin(xData/10)

Define the data size and batch size:

# define the data size and batch sizenSamples = 1000batchSize = 100

Get Neural Network Programming with TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.