首页 > 解决方案 > 在 Google Collaboratory 中,告诉 AI/ML 在屏幕上显示/打印它预测的模型的代码是什么?

问题描述

请参阅下面的代码以了解基本的 ML 测试。我运行了这个,但想看看 AI 使用给定的 xs 和 ys 数组集预测的数学公式,以及训练的 x 值。

import tensorflow as tf
import numpy as np
from tensorflow import keras

model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])

model.compile(optimizer='sgd', loss = 'mean_squared_error')

xs = np.array([-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0], dtype=float)
ys = np.array([-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0], dtype=float)

model.fit(xs,ys,epochs=10)

print(model.predict([-2.5]))

标签: google-colaboratory

解决方案


推荐阅读