Now it’s time to train our first model. Before that let me tell you what Tensor Flow is.
TensorFlow is a free and open-source software library for dataflow and differentiable programming across a range of tasks. It is a symbolic math library, and is also used for machine learning applications such as neural networks. Now let’s jump to our ML model. In the last post we had loaded our linear data and also defined our features and labels.
Oh! Before proceeding we have to randomise our data. If Randomisation is not done our model may by-hard outputs rather than improving itself. To randomise data we do following

Now we’ll configure a linear regression model using LinearRegressor. We’ll train this model using the GradientDescentOptimizer, which implements Mini-Batch Stochastic Gradient Descent (SGD). The learning_rate argument controls the size of the gradient step. We do gradient clipping using ‘clip_gradients_by_norm’. Gradient clipping is done to make sure the magnitude of the gradients do not become too large during training, which can cause gradient descent to fail.

Now we configure our Linear Regressor with features and optimizer

Defining a Input Function
To import our data into our LinearRegressor, we need to define an input function, which instructs TensorFlow how to preprocess the data, as well as how to batch, shuffle, and repeat it during model training.
To do this First, we’ll convert our pandas feature data into a dict of NumPy arrays. We can then use the TensorFlow Dataset API to construct a dataset object from our data, and then break our data into batches of batch_size, to be repeated for the specified number of epochs (num_epochs).
So the complete code for input function will be this

Next Step is to Train our model
We can now call train() on our linear_regressor to train the model. We’ll wrap my_input_fn in a lambda so we can pass in my_feature and targets as arguments , and to start, we’ll train for 100 steps

Next lets Predict and evaluate our model

Hope all of you are understanding the topic. If you have any doubts the just comment I will get back to you soon. In the next post we will see how good our model is working. Note that this is very basic Linear Regression problem in further post I will be covering more complex one’s.
Link to my previous post : https://machinelearningpower.home.blog/2019/03/30/our-data-with-tensorflow-ml/
Link to my Blog : http://machinelearningpower.home.blog







