import tensorflow as tf
import numpy as np

# Sample data: Predicting a simple pattern (e.g., x^2 approximation)
X = np.array([[0], [1], [2], [3], [4]], dtype=float)
y = np.array([[0], [1], [4], [9], [16]], dtype=float)

# Define a simple neural network
model = tf.keras.Sequential([
    tf.keras.layers.Dense(10, activation='relu', input_shape=(1,)),
    tf.keras.layers.Dense(1)
])

# Compile the model
model.compile(optimizer='adam', loss='mse')

# Train the model
model.fit(X, y, epochs=100, verbose=0)

# Predict and display
predictions = model.predict(X)
print("Predictions vs Actual:")
for i in range(len(X)):
    print(f"Input: {X[i][0]}, Predicted: {predictions[i][0]:.2f}, Actual: {y[i][0]}")

# Optional: Visualize (simple plot)
import matplotlib.pyplot as plt
plt.scatter(X, y, color='blue', label='Actual')
plt.plot(X, predictions, color='red', label='Predicted')
plt.title("Simple Neural Network Prediction")
plt.xlabel("Input")
plt.ylabel("Output")
plt.legend()
plt.show()