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:
1 | 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()
:
02 | function myFunction( ) { |
06 | for ( let x = 0; x <= xMax; x++ ) { |
07 | let result = model.predict( tf.tensor( [ Number(x) ] ) ); |
08 | result.data( ).then( y => { |
10 | yArr.push( Number( y ) ); |
11 | if ( x == xMax ) { plot( xArr, yArr ) }; |
14 | 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.
|