DEV Community

Cover image for Machine Learning - Celsius to Fahrenheit
Sandeep Balachandran
Sandeep Balachandran

Posted on • Updated on

Machine Learning - Celsius to Fahrenheit

Hey I am here with the second part,

So let's start with a problem.
Suppose you were given the following input and output values.

details

So when you input a value of 0 you get an output value of 32.
8 -> 46.4
15 -> 59 and so on.

Take a closer look at these numbers and let me ask you a question.

Can you figure out what will be the output value if you put in 38 as the input value?

38 -> ?

sd

If you answered 100.4, you are correct.

F = C * 1.8 + 32 right?

  • Where the input refers to degrees in Celsius and are represented here by a letter C
  • The outputs refer to degrees Fahrenheit represented here by the letter F
  • In other words the inputs represent a temperature value in degrees Celsius and the outputs show the corresponding temperature in degrees Fahrenheit.

For example, an input value of 0 refers to a temperature of 0 degrees Celsius,
which corresponds to 32 degrees Fahrenheit.

We get 32 by multiplying 0 by 1.8 and adding 32 like we see here in this equation.

Similarly, an input value of 15 refers to a temperature of
15 degrees Celsius which corresponds to 59 degrees Fahrenheit.
We get 59 by multiplying 15 by 1.8 and adding 32 like we see here in this equation.

What your brain just did to figure out the relation between these particular inputs and outputs, that's exactly what machine learning does.

That is, given a set of inputs and their corresponding outputs,the machine-learning algorithms will figure out the correct algorithm to convert the inputs to the outputs.You can think of it this way, in traditional software development, the input and the algorithm is known and you write a function to produce an output. On the other hand with machine learning, the input and the output are known but the algorithm that creates the output given the input is not known.So in machine learning the algorithm has to be learned.
Let's see an example.

Suppose you wanted to write a computer program that can convert degrees Celsius to degrees Fahrenheit using the relation F equals C times 1.8 plus 32.
With traditional software development, this relation can be easily implemented in any programming language by using a function.
In Python for example, this function will look like this.

code

Here the function takes the input value C. Then computes the output value F using the explicit algorithm that you wrote down and finally returns the output value F. On the other hand, in the machine learning approach we have the input and the output but not the algorithm. So it looks something like above. The machine learning approach consists of using a neural network to learn the relation between these inputs and outputs.

You can think of a neural network as a stack of layers where each layer consists of some predefined Math and internal variables.The input value is fed to the neural network and follows through the stack of layers. The Math and the internal variables are applied to it and the resulting output is produced.In order for the neural network to learn the correct relationship between the inputs and the outputs, we have to train it.

We train our neural network by repeatedly letting the network try to map the input to the output. While training, tuning the internal variables in the layers until the network learns to produce the output given the inputs. As we will see, the training process to teach the network to tune it's internal variables is performed for thousands or even millions of iterations over the input and the output data.

In very simple terms,you can think of the machine learning algorithm as a function that can tune variables in order to correctly map some inputs to some outputs.

machine learning

Let us continue this to another one.

Top comments (0)