(canvas, coeffs)
| 224 | |
| 225 | // Generate x-y data based on the size of the canvas. |
| 226 | function generateXYData(canvas, coeffs) { |
| 227 | const data = []; |
| 228 | for (let x = -canvas.width / 2; x < canvas.width / 2; |
| 229 | x += canvas.width / 25) { |
| 230 | data.push([ |
| 231 | x, coeffs[0] * x * x * x + coeffs[1] * x * x + coeffs[2] * x + coeffs[3] |
| 232 | ]); |
| 233 | } |
| 234 | return data; |
| 235 | } |
| 236 | |
| 237 | // Fit a model and render the data and predictions. |
| 238 | async function fitAndRender() { |