TensorFlow.js Models (Cont.)
TensorFlow Optimizers
- Adadelta: Implements the Adadelta algorithm.
- Adagrad: Implements the Adagrad algorithm.
- Adam: Implements the Adam algorithm.
- Adamax: Implements the Adamax algorithm.
- Ftrl: Implements the FTRL algorithm.
- Nadam: Implements the NAdam algorithm.
- Optimizer: Base class for Keras optimizers.
- RMSprop: Implements the RMSprop algorithm.
- SGD: Stochastic Gradient Descent Optimizer.
Training the Model
Train the model (using xs
and ys
) with 500 repeats (epochs) by using the fit()
function:
model.fit( xs, ys, {epochs:500} ).then( ( ) => { myFunction( ) } );
|
Using the Model
After the model is trained, you can use it for many different purposes.
This example predicts 10
y
values, given 10
x
values by using the function
predict()
, and calls a function to plot the predictions in a graph by using the function
newPlot()
:
// Using the model
function myFunction( ) {
const xMax = 10;
const xArr = [ ];
const yArr = [ ];
for ( let x = 0; x <= xMax; x++ ) {
let result = model.predict( tf.tensor( [ Number(x) ] ) );
result.data( ).then( y => {
xArr.push( x );
yArr.push( Number( y ) );
if ( x == xMax ) { plot( xArr, yArr ) };
} );
}
document.getElementById( 'message' ).style.display = "none";
}
|
An Example of Tensorflow Projects
My mother never saw the irony in calling me a son-of-a-bitch.
|