Result Size: 300 x 150
x
 
<!DOCTYPE html>
<html>
<script src="../scripts/myailib.js"></script>
<script src="../scripts/myplotlib.js"></script>
<body>
<canvas id="myCanvas" width="400px" height="400px" style="width:100%;max-width:400px;border:1px solid black"></canvas>
<p>Навчи мене знаходити лінію, яка найкраще підходить:</p>
<p>
<button onclick="train(100)">100 разів</button>
<button onclick="train(200)">200 разів</button>
<button onclick="train(300)">300 разів</button>
<button onclick="train(500)">500 разів</button>
</p>
<div id="demo"></div>
<script>
// Створити об’єкт Trainer
xArray = [32,53,61,47,59,55,52,39,48,52,45,54,44,58,56,48,44,60];
yArray = [31,68,62,71,87,78,79,59,75,71,55,82,62,75,81,60,82,97];
let myTrainer = new Trainer(xArray, yArray);
// Створити об’єкт Plotter
let myPlotter = new XYPlotter("myCanvas");
myPlotter.transformXY();
myPlotter.transformMax(100, 100);
// Нанесіть точки
myPlotter.plotPoints(xArray.length, xArray, yArray, "blue");
function train(iter) {
  myTrainer.train(iter);
  // Відображення припущених результатів
  document.getElementById("demo").innerHTML =
  "<p>Slope: " + myTrainer.weight.toFixed(2) + "</p>" +
  "<p>Bias:  " + myTrainer.bias.toFixed(2) + "</p>" +
  "<p>Cost:  " + myTrainer.cost.toFixed(2);
  myPlotter.plotLine(0, myTrainer.bias, myPlotter.xMax,myPlotter.xMax*(myTrainer.weight)+(myTrainer.bias), "black");
}
</script>
</body>
</html>