| 41 | } |
| 42 | |
| 43 | export async function plotDataAndPredictions(container, xs, ys, preds) { |
| 44 | const xvals = await xs.data(); |
| 45 | const yvals = await ys.data(); |
| 46 | const predVals = await preds.data(); |
| 47 | |
| 48 | const values = Array.from(yvals).map((y, i) => { |
| 49 | return {'x': xvals[i], 'y': yvals[i], pred: predVals[i]}; |
| 50 | }); |
| 51 | |
| 52 | const spec = { |
| 53 | '$schema': 'https://vega.github.io/schema/vega-lite/v2.json', |
| 54 | 'width': 300, |
| 55 | 'height': 300, |
| 56 | 'data': {'values': values}, |
| 57 | 'layer': [ |
| 58 | { |
| 59 | 'mark': 'point', |
| 60 | 'encoding': { |
| 61 | 'x': {'field': 'x', 'type': 'quantitative'}, |
| 62 | 'y': {'field': 'y', 'type': 'quantitative'} |
| 63 | } |
| 64 | }, |
| 65 | { |
| 66 | 'mark': 'line', |
| 67 | 'encoding': { |
| 68 | 'x': {'field': 'x', 'type': 'quantitative'}, |
| 69 | 'y': {'field': 'pred', 'type': 'quantitative'}, |
| 70 | 'color': {'value': 'tomato'} |
| 71 | }, |
| 72 | } |
| 73 | ] |
| 74 | }; |
| 75 | |
| 76 | return renderChart(container, spec, {actions: false}); |
| 77 | } |
| 78 | |
| 79 | export function renderCoefficients(container, coeff) { |
| 80 | document.querySelector(container).innerHTML = |