From 2465c300c1b31ded8881400a1388a6c391890b93 Mon Sep 17 00:00:00 2001 From: chaxus Date: Tue, 7 Nov 2023 00:37:00 +0800 Subject: [PATCH] feat: add linear modal --- packages/ml/client/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/ml/client/index.tsx b/packages/ml/client/index.tsx index 7ef2674d8..fe7269a88 100644 --- a/packages/ml/client/index.tsx +++ b/packages/ml/client/index.tsx @@ -47,11 +47,17 @@ const createModal = () => { const model = tf.sequential() model.add(tf.layers.dense({ - units: 1, + units: 4, useBias: true, activation: 'linear', inputDim: 1 })) + + const optimizer = tf.train.sgd(0.1) + model.compile({ + loss: "meanSquaredError", + optimizer + }) return model } const tfTensor = async () => { @@ -88,10 +94,13 @@ const tfTensor = async () => { // 分割测试集和训练集 const [trainingFeatureTensor, testingFeatureTensor] = tf.split(normaliseFeatureTensor.tensor, 2) const [trainingLabelTensor, testingLabelTensor] = tf.split(normaliseLabelTensor.tensor, 2) - // 创建模型 + // 创建模型 const modal = createModal() modal.summary() tfvis.show.modelSummary({ name: "Modal summary" }, modal) + // 了解 layer + const layer = modal.getLayer(undefined, 0) + tfvis.show.layer({ name: "Layer 1" }, layer) } const App = () => {