codigo de red neuronal con telsorflow.js

PHOTO EMBED

Fri Dec 09 2022 15:27:15 GMT+0000 (Coordinated Universal Time)

Saved by @modesto59 #html

/* function show(){

// Obtener los valores de entrada del formulario
const reticulacion = parseInt($("#level1" ).val());
const lobinfe = parseInt($("#level2").val());
const esmerilado = parseInt($("#level3" ).val());
const bronquiecta = parseInt($("#level4" ).val());
const axial = parseInt($("#level5").val());
const panamiel = parseInt($("#level6").val());
const atrapaereo = parseInt($("#level7").val());
const lobsuperior = parseInt($("#level8").val());
const noduloesme = parseInt($("#level9").val());
const noperilinfa= parseInt($("#level10").val());
const franja = parseInt($("#level11").val());
const consolida= parseInt($("#level12").val());
const engrosabronqui= parseInt($("#level13").val());
const esmeriquiste= parseInt($("#level14").val());
const quistes= parseInt($("#level15").val());

// Crear un tensor de entrada a partir de los valores del formulario
const input = tf.tensor2d([[reticulacion, lobinfe, esmerilado, bronquiecta, axial, panamiel, atrapaereo, lobsuperior, noduloesme, noperilinfa, franja, consolida, engrosabronqui, esmeriquiste, quistes]]); */


/* // create a simple feed forward neural network with backpropagation
const model = tf.sequential();
model.add(tf.layers.dense({units: 7, activation: 'sigmoid', inputShape: [15]}));
model.add(tf.layers.dense({units: 10, activation: 'softmax'}));
model.compile({optimizer: 'sgd', loss: 'categoricalCrossentropy', learningRate: 0.3});

// train the model with the input-output pairs
const xs = tf.tensor2d([
    [0,1,1,0,0,0,0,0,0,0,0,0,0,0,0],
    [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],
    [0,1,1,0,0,0,0,0,0,0,0,0,0,0,1],
    [0,0,1,0,0,0,0,1,1,0,0,0,0,0,0],
    [1,1,1,1,0,0,0,0,0,0,0,0,0,1,0],
    [0,1,1,0,1,0,0,1,0,0,0,1,1,0,0],
    [0,0,0,0,1,0,0,1,0,1,0,0,1,0,0],
    [1,1,0,1,0,0,0,0,0,0,0,0,0,0,0],
    [1,1,0,1,0,1,0,0,0,0,0,0,0,0,0],
    [1,1,1,1,1,0,0,0,0,0,1,0,0,0,0],
    [1,0,1,1,1,1,1,1,1,0,0,0,0,0,0],
    ...
]);
const ys = tf.tensor2d([
    [0,1,0,0,0,0,0,0,0,0],
    [0,0,1,0,0,0,0,0,0,0],
    [0,0,0,1,0,0,0,


    model.fit(xs, ys, {
  epochs: 10,
  batchSize: 32,
  shuffle: true
});



RED NUERONAL CON TENSORFLOW.JS

/* creame una red neuronal con tensorflow.js */

const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
model.fit(xs, ys, {epochs: 10}).then(() => {
  model.predict(tf.tensor2d([5], [1, 1])).print();
});
content_copyCOPY