Why Tensor?

TensorFlow is an open-source end-to-end platform for machine learning. It provides a comprehensive ecosystem of tools for developers, enterprises, and researchers who want to push the state-of-the-art of machine learning and build scalable machine learning-powered applications. TensorFlow was designed to help you learn to build models easily. With an intuitive easy-to-use set of APIs that makes it simple for you to learn and implement Machine Learning, Deep Learning and Scientific Computing.

TensorFlow provides a rich collection of tools for building models. These include data pre-processing, data ingestion, model evaluation, visualization and serving.

  • Data pre-processing the most important step in the data mining process, even though data preparation and filtering process take a significant amount of time. Often, given high value, because to deal with faulty Data-Collection methods resulting in missing values, out-of-range values (e.g., age: 1000). To say a few data pre-processing steps include normalization, transformation, treating missing values etc.,
  • Data ingestion plays a key role by allowing companies to move, store, integrate and further analyze data across many sources to make predictions and plan for upcoming needs despite many data ingestion challenges includes slow, complex and expensive.
  • A model evaluation which helps to find out the best model that represents our data as well as how well it will predict. With evaluation metrics, we can measure the goodness of fit between our model and data which emphasises prediction accuracy and to compare different models.
  • Visualization: TensorBoard is a suite of web applications for examining and understanding model graphs to track and visualize loss and accuracy. TensorBoard supports five visualizations i.e., to display images, text, audio, histograms and graphs.
  • Serving: TensorFlow serving is designed for production environments. TensorFlow Serving makes it easy to deploy new algorithms.

But it’s not just for building models. You can easily train and deploy your model anywhere with TensorFlow. It’s designed to be highly portable, running on a variety of devices and platforms. It can scale from a single CPU to a GPU or cluster of GPUs, all the way up to a multi-node TPU infrastructure. TensorFlow also allows for powerful experimentation with the flexibility to quickly implement state-of-the-art models, TensorFlow can power your research into new techniques to solve novel problems and solves everyday machine learning problems. From healthcare to social networks and e-commerce, TensorFlow can fit into any industry to solve their biggest problems.

Some case studies

  • Airbnb improves the guest experience by using TensorFlow to classify images and detect objects at scale.
  • Carousell uses TensorFlow to improve the buyer and seller experience.
  • Coca-Cola used TensorFlow to achieve a long-sought frictionless proof-of-purchase capability.
  • Paypal is using TensorFlow to stay at the cutting edge of Fraud Detection.

Some other use cases include diagnosis of diabetic retinopathy, helping rural farmers spot diseased plants, and predicting extreme weather conditions with fast debugging and the ability to apply state of the art ML models. And to top it all off, TensorFlow derives its roadmap from the needs of its users.

“How machine learning works is that the model will guess the relationship between the numbers”.

Basic Hello World example

Let’s walk through a basic Hello world example of building a machine learning model:

Take a look at these numbers

X = -1, 0, 1, 2, 3, 4,

Y = -3, -1, 1, 3, 5, 7

Can you see the relation between X and Y values?

It is actually Y = 2X – 1.

So, if u see it how did you get that, maybe you noticed Y value increases by 2 and X value increases by only 1. And then you may have seen when X was 0 then Y was -1, we figured Y = 2X – 1. We guessed this and this could work with all the remaining numbers this is the principle all machine leaning works on.

Let’s write a machine learning code that figures out what matches these numbers to each other.

Let’s define the model before writing the simplest possible neural network. A model is a trained neural network which in this case, is a single layer indicated by the ‘keras.layers.Dense code’. What is dense? A dense is a layer of connected neurons.

model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])

This layer has a single neuron in it, indicated by units = 1. We also feed a single value into the neural network which is the X value and we will have the neural network predict what the Y would be for that X. That is why input_shape is one value

model.compile(optimizer = ‘sgd’, loss = ‘mean_squared_error’)

Before compiling model we should know about two functions i.e., the loss and optimizer. These are the key to machine learning. How machine learning works is that the model will guess the relationship between the numbers.

For example, it might guess that Y = 5X + 5. And when training, it will then calculate how good or how bad that guess is, using loss function. And then, it will use the optimizer function to generate another guess. The logic is that the combination of these two functions will slowly get us closer and closer to the correct formula.


xs = np.array([ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype = float)

ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype = float)

model.fit(xs, ys, epochs = 500)

In this case, it will go through that loop 500 times, making a guess, calculating how accurate that guess is and then using the optimizer to enhance that guess, and so on. The data itself is set up as an array of Xs and Ys, and our process of matching them to each other is in the fit method of the model. We say, “fit the Xs to the Ys and try this 500 times.”

When it’s done, we will have a trained model. So, now you can try to predict a Y value for a given X.

print(model.predict([10.0]))

Predict the Y when X equals to 10. You might think that the answer is 19, right? But it isn’t. It’s something like 18.9998. It is close to 19, but it’s not quite there. Why do you think that would be?

Well, the computer was trained to match only six pairs of numbers. It looks like a straight-line relationship between them, for those six, but it may not be a straight line for values outside of those six. There’s a very high probability that it is a straight line, but we cannot be certain. And this probability is built into the prediction, so it is telling us very close to 19, instead of exactly 19.

So far, we have learned what is TensorFlow, what tools TensorFlow provides and how to use them and use cases of TensorFlow in real-world which drives impactful solutions to the ultra-modern problems and demonstration of building a basic machine learning model in TensorFlow.