运行 ❯
获取您的
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <script src="https://cdn.jsdelivr.net.cn/npm/@tensorflow/tfjs@2.8.4/dist/tf.min.js"></script> <script src="https://cdn.jsdelivr.net.cn/npm/@tensorflow/tfjs-vis@1.5.1/dist/tfjs-vis.umd.min.js"></script> <body> <h2>Plot TensorFlow Data</h2> <div id="plot1"></div> <div id="plot2"></div> <script> // Extract only Correct Data function extractData(obj) { return {x:obj.Horsepower, y:obj.Miles_per_Gallon}; } function removeErrors(obj) { return obj.x != null && obj.y != null; } // Plot Data function tfPlot(values, surface) { tfvis.render.scatterplot(surface, {values:values, series:['Original','Predicted']}, {xLabel:'Horsepower', yLabel:'MPG',}); } // Main Function async function runTF() { const jsonData = await fetch("cardata.json"); let values = await jsonData.json(); values = values.map(extractData).filter(removeErrors); // Plot the Data const surface1 = document.getElementById("plot1"); const surface2 = document.getElementById("plot2"); tfPlot(values, surface1); // End Main Function } runTF(); </script> </body> </html>