<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.8.4/dist/tf.min.js"></script>
<body>
<h2>Fetch TensorFlow Data</h2>
<div id="demo"></div>
<script>
function extractData(obj) {
return {x:obj.Horsepower, y:obj.Miles_per_Gallon};
}
function removeErrors(obj) {
return obj.x != null && obj.y != null;
}
async function runTF() {
const jsonData = await fetch("cardata.json");
let values = await jsonData.json();
values = values.map(extractData).filter(removeErrors);
let text = "";
for (let i = 0; i < values.length; i++) {
text += "x: " + values[i].x + " y:" + values[i].y + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
runTF();
</script>
</body>
</html>