Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!