BrainJS ReferenceError: brain is not defined
BrainJS ReferenceError: brain is not defined
我正在学习如何使用 brain.js 使用神经网络的教程,当我尝试 运行 代码时,它给我一个 ReferenceError: brain is not defined 我已经通过 npm 安装了并在 HTML.
上安装 CDN
const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];
net.train(trainingData);
console.log(net.run([0, 0]));
这是 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="//unpkg.com/brain.js"></script>
<script src="index.js"></script>
</head>
<body>
</body>
</html>
````
尝试添加显式协议 https://
而不是仅使用 //
。当我这样做时,您的代码对我有用。
const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];
net.train(trainingData);
console.log(net.run([0, 0]));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/brain.js"></script>
<script src="index.js"></script>
</head>
<body>
</body>
</html>
我正在学习如何使用 brain.js 使用神经网络的教程,当我尝试 运行 代码时,它给我一个 ReferenceError: brain is not defined 我已经通过 npm 安装了并在 HTML.
上安装 CDNconst net = new brain.NeuralNetwork({ hiddenLayers: [3] });
const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];
net.train(trainingData);
console.log(net.run([0, 0]));
这是 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="//unpkg.com/brain.js"></script>
<script src="index.js"></script>
</head>
<body>
</body>
</html>
````
尝试添加显式协议 https://
而不是仅使用 //
。当我这样做时,您的代码对我有用。
const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
const trainingData = [
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] },
{ input: [1, 0], output: [1] },
{ input: [1, 1], output: [0] }
];
net.train(trainingData);
console.log(net.run([0, 0]));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/brain.js"></script>
<script src="index.js"></script>
</head>
<body>
</body>
</html>