Advertisement
hendriawan

day2-01-regressi

Nov 28th, 2022 (edited)
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import numpy as np
  2. from tensorflow.keras.models import Sequential
  3. from tensorflow.keras.layers import Dense
  4.  
  5. train_x=np.arange(-20,20,0.25)
  6. train_y=np.sqrt((2*train_x**2)+1)
  7.  
  8. model = Sequential()
  9.  
  10. model.add(Dense(8,input_dim=1,activation='relu'))  # input hidden ke input
  11. model.add(Dense(4, activation = 'relu'))   # dim layer
  12. model.add(Dense(1, activation = 'linear')) # ouput layer
  13.  
  14. model.compile (loss = 'mean_squared_error', optimizer = 'adam')
  15. model.fit(train_x,train_y,batch_size=20, epochs=10000,verbose=2)
  16.  
  17. print(model.summary())
  18. model.save("model.h5")
  19.  
  20. # test kasus
  21. x=np.array([26])
  22. predict= model.predict(x)
  23. print("f(26) =", predict )
  24.  
  25.  
  26.  
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement