将预测值 Y 获取到 tensorflow.js 中一定数量的 X 值

Getting predicted value Y to a certain number of X values in tensorflow.js

我是机器学习的初学者,因为我喜欢使用 javascript,我最近开始使用 tensorflow.js 库。我同时处理了将曲线拟合到合成数据,这是一个回归问题和MNIST数字识别 卷积层是一个 分类 问题,现在我有点知道数据如何流经层。

但现在我想对图书馆做更多的事情。因此,我从开放数据集中下载了 wine-quality.csv 数据集,该数据集包含葡萄酒中不同数量的成分,并评估了葡萄酒的一定质量。来自 .csv 的解析数据看起来有点像这样。

xs : [[5]]
ys : [[0.5,0.004,0.003,0.1,4,0.11]]

现在我想将葡萄酒的数量 (YS) 传递给模型,我希望模型预测我的质量 (XS) 的酒。而且我不知道如何构建这个想法。我怎样才能做到这一点?

您的输入数组的维度为 1,大小为 6。可以使用随机梯度下降优化器定义以下模型。

const model = tf.sequential();

// First define the model
model.add(tf.layers.dense({units: 1, inputShape: [6]}));
// use the sgd optimizer
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
const x = tf.tensor2d([[0.5,0.004,0.003,0.1,4,0.11]])
const y = tf.tensor2d([[5]])
//training data
model.fit(x, y)
//test data
model.predict(tf.tensor2d([0.5,0.004,0.003,0.1,4,0.11], [1, 6])).print()
<html>
  <head>
    <!-- Load TensorFlow.js -->
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.12.0"> </script>
  </head>

  <body>
  </body>
</html>