It is my first steps in the tensorflow.
Idea
There is some pattern of numbers (the array of numbers: Pattern = number[]). And the category that corresponds to this pattern (the number from 0 to 2: Category = 0 | 1 | 2). I have follow the structure data: xs = Pattern[], ys = Category[].
For example:
xs = [[1, 2, 3, 4], [5, 6, 7, 8], ..., [9, 10, 11, 12]];
ys = [1, 0, ..., 2];
I want the neural network to find a match between xs[0] and xy[0], and so on. I want to pass the neural network data like [1, 2, 3, 4] and get a result close to 1.
model.predict(tf.tensor([1, 2, 3, 4])) // ≈1
My code
import * as tf from '@tensorflow/tfjs';
require('@tensorflow/tfjs-node');
const xs = tf.tensor2d([
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
]);
const ys = tf.tensor1d([0, 1, 2]);
const model = tf.sequential();
model.add(tf.layers.dense({ units: 4, inputShape: xs.shape, activation: 'relu' }));
^ - Pattern length, it is constant
model.add(tf.layers.dense({ units: 3, activation: 'softmax' }));
model.compile({ optimizer: 'adam', loss: 'categoricalCrossentropy', metrics: ['accuracy'] });
model.fit(xs, ys, { epochs: 500 });
I get follow error:
Error when checking input: expected dense_Dense1_input to have 3 dimension(s). but got array with shape 3,4
I don't understand how to explain my data structure for the neural network.