# TensorFlow (Intermediate): Linear Regression

In this course, we are going to solve a linear regression problem with the help of TensorFlow and in the eager execution mode of TensorFlow. Let’s say we have an equation like this: `y = Wx + b`. And let’s say we have a lot of values for `y` and `x`. Given that, can we find out the values for `W` and `b`? This is a basic machine learning problem and this is pretty much the fundamental concept of how we make machines learn. Essentially, we just make machines find the optimal values for parameters (like `W` and `b` in this case), given an assumed model and a bunch of data. So, we try to find the values for parameters which will best fit the data that we have.

Duration (mins)

Learners

#### 5.0 / 5

Rating

We will cover the following tasks in 36 minutes:

### Introduction

Normally, when you use TensorFlow to create and train machine learning models, you need to build computational graphs first required for your model training first and then run those graphs later to actually perform the computations. However, this approach is not very easy or intuitive to use. In production setting, this may not be a big problem but if you’re just researching and experimenting with your potential models, then this traditional approach can slow things down.

This is where eager execution comes in. TensorFlow’s eager execution facilitates an imperative programming environment that allows the programmer to evaluate operations immediately, instead of first creating computational graphs to run later.

### Data Synthesis

We are going to synthesise our data which we will use to solve a linear regression problem. Now, usually you will get this data from observation but we are just learning here. So, for our purpose we will generate this data.

A good model will have values for `W` and `b` such that the cost on the entire set is minimized. We can say that a good indication of one single prediction being a good prediction would be that the squared difference between the prediction and the actual value for `y` for the same `x` is low. If this value is high, then the prediction is obviously not good.

And an indication of a good model would be if these loss values for all values for `x`, put together, is low. This is called cost of a model. But how do we know if a cost is low or high?

We can use an algorithm called gradient descent which starts off with some arbitrary values for `W` and `b` and then we calculate the gradients of our cost function with respect to these values. We then take a small step in the direction of these slopes to, hopefully, move closer to a minima.

### Linear Regression Model

Based on our understanding so far, we will need to define four functions in our Linear Regression Model: the initializer where we set the initial values for model’s parameters, a cost function, a predict function and a train function.

The predict function will take a inputs and predict outputs based on latest values of parameters `W` and `b`. The cost function will take this prediction and the actual outputs and will calculate the cost J based on that.

### The Training Loop

The train function will take an inputs and outputs and will run a loop for a few iterations that we can decide beforehand. In each iteration, the values for `W` and `b` will be updated.

### Training the Model

We have actually done bulk of the work in the previous chapter and now we just need to call the train method (defined previously) after instantiating our model. This will fit out model to the given data, giving us a model with optimal values for our parameters!

## Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

## Reviews

There should be a way to get some quick questions answered..

Sharma Kunapalli

I am a machine learning engineer with focus in computer vision and sequence modelling for automated signal processing using deep learning techniques. My previous experiences include leading chatbot development for a large corporation.

##### How is this different from YouTube, PluralSight, Udemy, etc.?
In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Amit Yadav) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
##### Can I buy Rhyme sessions for my company or learning institution?
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select projects and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at help@rhyme.com
##### What kind of accessibility options does Rhyme provide?
Rhyme's visual instructions are somewhat helpful for reading impairments. The Rhyme interface has features like resolution and zoom that are slightly helpful for visual impairment. And, we are currently developing a close-caption functionality to help with hearing impairment. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. However, we still have a lot of work to do. If you have suggestions for accessibility, please email us at accessibility@rhyme.com
##### Why don't you just use containers or virtual browsers?
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
##### I have a different question
Please email us at help@rhyme.com and we'll respond to you within one business day.

## More Projects by Amit Yadav

31 minutes
38 minutes
###### Computer Vision with TensorFlow: Deploy Your Model
1 hour and 1 minute
###### TensorFlow (Intermediate): Neural Networks with TensorFlow Core
1 hour and 12 minutes
53 minutes
34 minutes
51 minutes
###### Google Cloud AI: End to End Deep Learning Part 2
1 hour and 7 minutes
34 minutes
48 minutes
27 minutes
51 minutes
60 minutes
###### TensorFlow (Beginner): Predicting House Prices
1 hour and 8 minutes
###### Computer Vision with TensorFlow: Object Classification & Detection
1 hour and 4 minutes
56 minutes
###### Amazon SageMaker: Custom Scripts
1 hour and 14 minutes
###### Amazon SageMaker: Object Detection
1 hour and 24 minutes
55 minutes
49 minutes
49 minutes
###### Amazon SageMaker: Semantic Segmentation
1 hour and 3 minutes
46 minutes
###### TensorFlow (Advanced): Neural Style Transfer
1 hour and 5 minutes
48 minutes
52 minutes