Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
how to format input data in tensorflow.js?

I want a model that takes 6 inputs and predict 1 output. It has something to do with predicting how long a task will take.

Here is what I got so far:

 const model = tf.sequential();
        model.add(tf.layers.dense({units: 1, inputShape: [1]}));
        model.compile({
            optimizer: 'sgd',
            loss: 'meanSquaredError'
        });

        async function createAndTrainModel(){
            var xs = tf.tensor2d([40, 1, 0], [20, 1, 0]);
            var ys = tf.tensor2d([45], [25]);
            // Here I wanted to explain that 40,1,0 must be predicted as 45.
            // And a combination of 20, 1, 0 must be predicted as 25.

            await model.fit(xs, ys, {epochs: 500});
            console.log("done training model!");

            var result = model.predict(
                tf.tensor([-40, 15, 0])
            );

            result = result.dataSync();
            console.log(result);
        }

I have a working example in Python, but I really want to do this in JavaScript. I do not understand what an input shape is. All I think of is a circle, triangle and a square...

Almost every tutorial I found assumes you have some knowledge in how tensorflow works, what a 'dimension' is (whatever that may be)

Can someone solve my problem and explain to me what is happening here? What is an input shape? What is a dimension? Why is it used like that? I understand what an array is, but I cannot understand why you need to define a dimension or something like that.

My code in Python, which works:

import keras.models
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

import tensorflowjs as tfjs

# Configure Training Data
data = pd.read_csv("task-data.csv", sep=";")
data = data[["actual_time", "moeilijkheid", "eerder_gedaan", "leukheid"]]
celsius_q = np.array(data.drop(["actual_time"], 1), dtype=int)
fahrenheit_s = np.array(data["actual_time"], dtype=int)

# Creating and Training the Model
l0 = tf.keras.layers.Dense(units=1)
model = tf.keras.Sequential([l0])
model.compile(loss="mean_squared_error", optimizer=tf.keras.optimizers.Adam(0.1), metrics=['accuracy'])
history = model.fit(celsius_q, fahrenheit_s, epochs=5000, verbose=False)
print("Finished training the model.")

predictions = model.predict(celsius_q)

print(model.predict([[
    4,1,1,5,8,2
]]))

model.evaluate(celsius_q, fahrenheit_s)

# Saving the Model
tfjs.converters.save_keras_model(model, 'models')

the data is like this:

"actual_time";"moeilijkheid";"eerder_gedaan";"leukheid"

45;4;1;0

25;2;1;0
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To oversimplify, tensor can be just a single number or an array of higher complexity. 1d tensor is a number, 2d tensor is an array. 3d tensor is array of arrays. 4d tensor is ... well, you get it :)

your data

"actual_time";"moeilijkheid";"eerder_gedaan";"leukheid"

has a single dimension and 4 fields
how many records do you expect? tensor shape would be [4, numRecords] or [numRecords, 4], depending how you iterate though it.

lets imagine you want to have 10 such datasets you want to analyze them in paralel? dimension would be [10, 4, numRecords]

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda