ml5.js错误:检查时出错:预期density_Dense1_input的形状为[null,250],但数组的形状为[1,1]

时间:2020-10-16 02:55:22

标签: javascript machine-learning

我正在尝试使用ml5.js创建模型,并且在控制台中收到一条错误消息: <div id="question1">question 1 <button class=option1>1</button> <button class=option2>2</button> <button class=option3>3</button> <button class=option4>4</button> </div> <div id="question2">question 2 <button class=option1>1</button> <button class=option2>2</button> <button class=option3>3</button> <button class=option4>4</button> </div> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script>

使用此命令,您可以将所有项目文件复制到计算机上进行测试:

Error: Error when checking : expected dense_Dense1_input to have shape [null,250] but got array with shape [1,1].

sketch.js

git clone https://github.com/anonym2048/mystuff.git

index.html

var options = {
     task: "regression",
     debug: true,
     dataUrl: "germany_covid.csv",
     inputs: ["Date"],
     outputs: ["Cases"],
     layers: [
          {
               type: 'dense',
               units: 16,
               inputShape: [250], //what should I put here?
               activation: 'relu',
          },
          {
               type: 'dense',
               activation: 'sigmoid',
          },
     ],
};
     
var nn = ml5.neuralNetwork(options, train);

function train() {
     nn.normalizeData();
     
     var trainingOptions = {
          epochs: 256,
          batchSize: 500,
     };
     
     nn.train(trainingOptions, predict);
}

function predict(){
     nn.predict({"Date": "2020-10-20"}).then((result) => {
          console.log(result);
     });
}

csv文件:https://raw.githubusercontent.com/anonym2048/mystuff/main/germany_covid.csv

我希望它能在控制台中为我提供预测结果。

我尝试使用对象的“ inputShape”属性,但是当我将值从250更改为[1,1]时,模型的训练就没有开始。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

问题在于输入值必须是数字。我使用了字符串。