【发布时间】:2020-03-18 18:07:01
【问题描述】:
我正在努力学习机器学习的基础知识。我正在尝试训练 AI 的平方函数:2^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([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0], dtype=int)
ys = np.array([4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, 4096.0, 8192.0, 16384.0, 32768.0], dtype=int)
model.fit(xs, ys, epochs=1000)
print(model.predict([7.0]))
这应该打印 +- 128,但结果是在 2000 年,损失非常高。
如何优化这个神经网络,让它给我更准确的答案?
感谢您的宝贵时间。
【问题讨论】:
标签: python tensorflow neural-network