Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. function testModel(model, input, inputData, normalizationData) {
  2. const { inputMax, inputMin, labelMin, labelMax } = normalizationData;
  3.  
  4. // Generate predictions for a uniform range of numbers between 0 and 1;
  5. // We un-normalize the data by doing the inverse of the min-max scaling
  6. // that we did earlier.
  7. const [xs, preds] = tf.tidy(() => {
  8. //const xs = tf.linspace(0, 1, 63); //Using same fake data to test the model
  9. const xs = input; // Using the input data to test the model
  10. const preds = model.predict(xs.reshape([63, 1]));
  11.  
  12. const unNormXs = xs.mul(inputMax.sub(inputMin)).add(inputMin);
  13.  
  14. const unNormPreds = preds.mul(labelMax.sub(labelMin)).add(labelMin);
  15.  
  16. // Un-normalize the data
  17. return [unNormXs.dataSync(), unNormPreds.dataSync()];
  18. });
  19.  
  20. const predictedPoints = Array.from(xs).map((val, i) => {
  21. return { x: val, y: preds[i] };
  22. });
  23.  
  24. const originalPoints = inputData.map(d => ({
  25. x: d.claims,
  26. y: d.payment
  27. }));
  28.  
  29. tfvis.render.scatterplot(
  30. { name: "Model Predictions vs Original Data" },
  31. {
  32. values: [originalPoints, predictedPoints],
  33. series: ["original", "predicted"]
  34. },
  35. {
  36. xLabel: "Number of claims",
  37. yLabel: "Total Payment",
  38. height: 300
  39. }
  40. );
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement