from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
import numpy as np
X = np.linspace(-1, 1, 100)
noise = np.random.normal(0, 0.01, X.shape)
Y = X * 2 + 3 + noise
model = Sequential()
model.add(Dense(1, input_dim=1))
model.compile(optimizer="sgd", loss="mse")
for i in range(50):
model.fit(X, Y, batch_size=20)
W, b = model.layers[0].get_weights()
print("W=", W, "b=", b)
keras模拟线性回归
最新推荐文章于 2023-09-12 12:42:25 发布