第一个Keras程序
import keras
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense
model.compile(optimizer='sgd',loss='mse')
for step in range(3000):
cost = model.train_on_batch(x_data,y_data)
if step%500==0:
print('cost:',cost)
W,b = model.layers[0].get_weights()
print('W:',W,'b:',b)
y_pred = model.predict(x_data)
plt.plot(x_data,y_pred,'r-',lw=3)
plt.show()