fork download
  1. from tensorflow.keras.models import Sequential
  2. from tensorflow.keras.layers import Dense
  3. import numpy as np
  4.  
  5. # Creating dummy data
  6. X = np.array([[0], [1], [2], [3], [4], [5]])
  7. y = np.array([0, 1, 2, 3, 4, 5])
  8.  
  9. # Creating a simple neural network model
  10. model = Sequential([
  11. Dense(10, input_dim=1, activation='relu'),
  12. Dense(1) # Output layer
  13. ])
  14.  
  15. # Compiling the model
  16. model.compile(optimizer='adam', loss='mean_squared_error')
  17.  
  18. # Training the model
  19. model.fit(X, y, epochs=50, verbose=0)
  20.  
  21. # Making a prediction
  22. print("Prediction for input 6:", model.predict(np.array([[6]])))
  23.  
Success #stdin #stdout 2.73s 350408KB
stdin
Standard input is empty
stdout
Prediction for input 6: [[-2.4553885]]