import tensorflow as tf
import numpy as np
# 该神经网络只有一个结点,输入数据形状为单个数
model = tf.keras.Sequential([tf.keras.layers.Dense(units=1, input_shape=[1])])
# 为模型设置sgd优化器和均方误差损失
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=100)
print(model.predict([8.0]))
print("Here is what I learned:{}".format(model.get_weights()))
keras 线性拟合 基于tensorflow2.x
最新推荐文章于 2022-07-15 17:39:28 发布