import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import SimpleRNN, Dense, Input

rainfall = np.array([10, 12, 8, 15, 20, 18, 25, 30, 28, 35, 40, 38, 45], dtype=float)

def create_dataset(data, time_steps=4):
  X, y = [], []
  for i in range(len(data) - time_steps):
    X.append(data[i:i+time_steps])
    y.append(data[i+time_steps])
  return np.array(X), np.array(y)

X, y = create_dataset(rainfall, 4)
X = X.reshape((X.shape[0], X.shape[1], 1))

model = Sequential([
  Input(shape=(4, 1)),
  SimpleRNN(10, activation='tanh'),
  Dense(1)
])

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

model.fit(X, y, epochs=200, verbose=0)

test_input = np.array([[30, 28, 35, 40]])
test_input = test_input.reshape((1, 4, 1))
prediction = model.predict(test_input)

print("Predicted rainfall for next day:", prediction[0][0])