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

175
Views
model.predict in TensorFlowJS function returning undefined

i created a sequential model under nodejs and my model.predict().print function as well as the onbatchEnd callback keeps returning undefined even though i checked my training data tensors are working fine. here is my code

const utils = require('../utils/')
const tf = require ('@tensorflow/tfjs');


const model = tf.sequential();


model.add(tf.layers.dense({name: 'layer1', units: 32, inputShape: [30],activation: 'relu' }))
model.add(tf.layers.dense({name:'layer2',units: 1, activation: 'softmax'}))
;


model.compile({loss: 'meanSquaredError', optimizer: 'sgd',
             metrics: ['MAE']});


fs.readFile('../models/data.csv', 'utf8' , (err, data) => {
      
      if (err) {
        console.error(err)
        return
      }
      
     utils.removeHeaders(data).then(
     (newData)=>{ return utils.convertstringToArray(newData)})
    .then(firstArray =>{return utils.convertstringToArray2(firstArray) })
    .then(secondArray =>{return utils.convertstringToLastObject(secondArray)})
    .then(obj => {
        
        const xs = tf.tensor2d(obj.X, [18, 30],'int32');
        const ys = tf.tensor2d(obj.Y, [18, 1],'int32');



    model.fit(xs, ys, {epochs: 500, callbacks:{onBatchEnd}}).then((info) => {               model.predict(tf.tensor([[104,111,117,32,97,111,101,32,121,111,117,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32]])).print();
    }).catch(error=>console.log(error));
     })
 })
 
     function onBatchEnd(batch, logs) {
      console.log('Accuracy', logs.acc);
    }```   
about 4 years ago · Juan Pablo Isaza
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!