Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function testModel(model, input, inputData, normalizationData) {
- const { inputMax, inputMin, labelMin, labelMax } = normalizationData;
- // Generate predictions for a uniform range of numbers between 0 and 1;
- // We un-normalize the data by doing the inverse of the min-max scaling
- // that we did earlier.
- const [xs, preds] = tf.tidy(() => {
- //const xs = tf.linspace(0, 1, 63); //Using same fake data to test the model
- const xs = input; // Using the input data to test the model
- const preds = model.predict(xs.reshape([63, 1]));
- const unNormXs = xs.mul(inputMax.sub(inputMin)).add(inputMin);
- const unNormPreds = preds.mul(labelMax.sub(labelMin)).add(labelMin);
- // Un-normalize the data
- return [unNormXs.dataSync(), unNormPreds.dataSync()];
- });
- const predictedPoints = Array.from(xs).map((val, i) => {
- return { x: val, y: preds[i] };
- });
- const originalPoints = inputData.map(d => ({
- x: d.claims,
- y: d.payment
- }));
- tfvis.render.scatterplot(
- { name: "Model Predictions vs Original Data" },
- {
- values: [originalPoints, predictedPoints],
- series: ["original", "predicted"]
- },
- {
- xLabel: "Number of claims",
- yLabel: "Total Payment",
- height: 300
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement