Hi
- User
Hi
- Assistant
Hello! How can I assist you today?
- User
I want to use machine learning with nodejs to predict whether a given stock I should buy/sell/hold and at what prices. I want this function to return a promise in this given format { action: 'buy/sell', price: '#', sell: '#' }
I will feed data to the function in this following format,
const data = [ { date: '2022-05-03T09:30:00', high: 420.89, low: 418.24, open: 419.99, close: 419.98, volume: 100 }, { date: '2022-05-03T09:32:00', high: 419.89, low: 416.24, open: 416.99, close: 419.28, volume: 200 }, { date: '2022-05-03T09:34:00', high: 418.89, low: 415.24, open: 415.99, close: 418.98, volume: 150 } ];The function does not have to worry about fetching the ticket prices, the interval between the prices is of 2 minutes and I want it to remain that way to analyze the data.
I understand these will just be predictions, and I'll have the final say on anything so this will not be used for an automation but just as a tool to then validate myself if this is an accurate prediction the machine did.
I also do not want to use tensorflow or python for this, only nodejs. Preferably I'd like to use brain.js
So to recap, I'll give you an array of objects you'll lookback through a given set of indexes, and make a prediction
- Assistant
- User
I'm receiving this error,
TypeError: Cannot read properties of undefined (reading 'buffer') at getTypedArrayFn (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4365:15) at NeuralNetwork.formatData (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:5087:33) at NeuralNetwork.prepTraining (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4807:35) at NeuralNetwork.train (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4822:56) at trainModel (/home/pedro/Documents/projects/Stocks-Tracker/new.js:35:7) at /home/pedro/Documents/projects/Stocks-Tracker/new.js:50:7 at new Promise (<anonymous>) at predict (/home/pedro/Documents/projects/Stocks-Tracker/new.js:47:10) at Object.<anonymous> (/home/pedro/Documents/projects/Stocks-Tracker/new.js:63:1) at Module._compile (node:internal/modules/cjs/loader:1159:14) - Assistant
This error occurs because there is a mismatch between the input data and the expected format by brain.js. Specifically, brain.js expects the input data to be an array of arrays, where each subarray represents a set of input values.
To fix this error, you can modify the
preprocessDatafunction to return an array of arrays, instead of an array of objects. Here's an updated version of the function:function preprocessData(data) { const interval = 3; // 3 intervals of 2 minutes each const inputData = []; for (let i = 0; i < data.length - interval + 1; i++) { const inputRow = []; for (let j = i; j < i + interval; j++) { inputRow.push(data[j].close); } inputData.push(inputRow); } return inputData; } - User
TypeError: Cannot read properties of undefined (reading 'buffer') at getTypedArrayFn (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4365:15) at NeuralNetwork.formatData (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:5087:33) at NeuralNetwork.prepTraining (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4807:35) at NeuralNetwork.train (/home/pedro/Documents/projects/Stocks-Tracker/node_modules/brain.js/dist/index.js:4822:56) at trainModel (/home/pedro/Documents/projects/Stocks-Tracker/new.js:36:7) at /home/pedro/Documents/projects/Stocks-Tracker/new.js:51:23 at new Promise () at predict (/home/pedro/Documents/projects/Stocks-Tracker/new.js:48:10) at Object. (/home/pedro/Documents/projects/Stocks-Tracker/new.js:65:1) at Module._compile (node:internal/modules/cjs/loader:1159:14)
- Assistant
This error can happen if your input data has
undefinedvalues, which are not acceptable to brain.js. To fix this error, you can modify thepreprocessDatafunction to check forundefinedvalues and replace them with 0.Here's an updated version of the
preprocessDatafunction with the added condition:function preprocessData(data) { const interval = 3; // 3 intervals of 2 minutes each const inputData = []; for (let i = 0; i < data.length - interval + 1; i++) { const inputRow = []; for (let j = i; j < i + interval; j++) { const closePrice = data[j]?.close || 0; // check for 'undefined' values and replace with 0 inputRow.push(closePrice); } inputData.push(inputRow); } return inputData; }After making this change, you can try running the
predictfunction again to see if the error is resolved.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.