TensorFlow Train/test /evaluation flow
TensorFlow Train/test /evaluation flow
step1:
Choose a model
First, we'll need to choose which machine learning algorithm we want to use to build our model. we can pick any standard machine learning algorithm but in this section, we will be using neural networks.
then we can start with the training phase.
step2:
we train the algorithm by showing its training data and the expected output for the data and it has to figure out how to come up with the expected result.
in other words, the algorithm learns how to transform the input to produce the correct output.
for example, we can train it to do multiplication by showing it two numbers and the expected result and it will eventually work out that we want to multiply the two numbers. After we train the model, we will load up the second set of data, which has never seen before called the testing data set. This is the test phase, we will feed this testing data through the model and make sure it is able to predict the correct result even though it has never seen this data before. This shows that the model actually learned how to solve the problem in a general way and didn't just memorize the answers for the training data.
Step3:
Evaluation phase
finally, once the model is trained and tested, we can use it. this is the evaluation phase. we'll pass in new data and it will tell us the answer is calculated.
in TensorFlow, we will follow these same steps when building a model. but with TensorFlow, we have to set up a lot of the mechanics of this ourselves.
first, we code our machine learning algorithm. we'll do that by building a computational graph. of operations that TensorFlow can run. Here's how we'll implement a neural network. First, we'll define each layer of the neural network and connect them together so that data flows from the first layer through to the last layer. then we'll add the placeholder node that represents the data that will be fed in a s input to the neural network. and another placeholder node that represents the output or values predicted by the neural network. next, we need a way to measure the accuracy of the neural network's predictions. we'll define the function that measures the accuracy of each prediction during the training process. this is called a "loss function".
the loss function gets added to the graph as its own operation. then we have to create an optimizer function that tells TensorFlow how we want to train the model. when we run this function, it will perform one training step on our model. Tensorflow provides many pre-built optimizer functions. so usually we just have to tell it which one to use and we don't need to implement custom code. we'll call this node training operation. the training operation will train the neural network by looking at the results of the loss function and using that to adjust the weights of each layer in the neural network until they produce the desired output. because this is a computational graph, there's no single start or end.
Comments
Post a Comment