HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
When a model is trained, the data is divided into small sets (batches).Each batch is then fed to the model.Shuffling is important to prevent the model getting the same data over again.If using the same data twice, the model will not be able to generalize the dataand give the right output. Shuffling gives a better variety of data in each batch
Always shuffle data before training.
When a model is trained, the data is divided into small sets (batches). Each batch is then fed to the model. Shuffling is important to prevent the model getting the same data over again. If using the same data twice, the model will not be able to generalize the data and give the right output. Shuffling gives a better variety of data in each batch.
tf.util.shuffle(data);
To use TensorFlow, input data needs to be converted to tensor data:
// Map x values to Tensor inputs
const inputs = values.map(obj => obj.x);
// Map y values to Tensor labels
const labels = values.map(obj => obj.y);
// Convert inputs and labels to 2d tensors
const inputTensor = tf.tensor2d(inputs, [inputs.length, 1]);
const labelTensor = tf.tensor2d(labels, [labels.length, 1]);
Data should be normalized before being used in a neural network.
A range of 0 - 1 using min-max are often best for numerical data:
const inputMin = inputTensor.min();
const inputMax = inputTensor.max();
const labelMin = labelTensor.min();
const labelMax = labelTensor.max();
const nmInputs = inputTensor.sub(inputMin).div(inputMax.sub(inputMin));
const nmLabels = labelTensor.sub(labelMin).div(labelMax.sub(labelMin));
A Machine Learning Model is an algorithm that produces output from input.
This example uses 3 lines to define a ML Model:
const model = tf.sequential();
model.add(tf.layers.dense({inputShape: [1], units: 1, useBias: true}));
model.add(tf.layers.dense({units: 1, useBias: true}));
Sequential ML Model
In a sequential model, the input flows directly to the output. Other models can have multiple inputs and multiple outputs. Sequential is the easiest ML model. It allows you to build a model layer by layer, with weights that correspond to the next layer.
TensorFlow Layers
Shapes and Units
Compile the model with a specified optimizer and loss function:
model.compile({loss: 'meanSquaredError', optimizer:'sgd'});
The compiler is set to use the sgd optimizer. It is simple to use and quite effective.