1. 程式人生 > >用Keras搭建神經網路 簡單模版(一)——Regressor 迴歸

用Keras搭建神經網路 簡單模版(一)——Regressor 迴歸

#training print("Training~~~~~~~~") for step in range(301): cost = model.train_on_batch(X_train,Y_train)#一批一批的資料,這裡一批選擇全部資料 if step %100==0: print('train cost:',cost) #test print('\nTesting~~~~~~~~') cost = model.evaluate(X_test,Y_test,batch_size=40) print('test cost:',cost) W,b = model.layers[0].get_weights()
print('Weights=',W,'\nbiases=',b) #plotting the prediction Y_pred =model.predict(X_test) plt.scatter(X_test,Y_test) plt.plot(X_test,Y_pred)