信创国产化替换如何推动企业自主创新与市场竞争力提升
907
2022-10-11
Keras Regressor 回归
import numpy as npnp.random.seed(1337)from keras.models import Sequentialfrom keras.layers import Denseimport matplotlib.pyplot as pltX = np.linspace(-1, 1, 200)np.random.shuffle(X)Y = 0.5 * X + 2 + np.random.normal(0, 0.05, (200, ))plt.scatter(X, Y)plt.show()X_train, Y_train = X[:160], Y[:160]X_test, Y_test = X[160:], Y[160:]model = Sequential()model.add(Dense(units=1, input_dim=1))model.compile(loss='mse', optimizer='sgd')for step in range(301): cost = model.train_on_batch(X_train, Y_train) if step % 100 == 0: print('train cost:', cost)cost = model.evaluate(X_test, Y_test, batch_size=40)W, b = model.layers[0].get_weights()print('Weights=', W, '\nbiases=', b)Y_pred = model.predict(X_test)plt.scatter(X_test, Y_test)plt.plot(X_test, Y_pred)plt.show()
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~