import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import LSTM, Dense
from keras.callbacks import ModelCheckpoint

# Load data from a Notebook file
def load_data(file_path):
    data = pd.read_csv(file_path, header=None, names=['input_data'])
    x = data['input_data'].values
    y = data['output_data'].values
    return x, y

# Preprocess data
def preprocess(x, y):
    x = np.reshape(x, (x.shape[0], 1, x.shape[2]))
    y = np.reshape(y, (y.shape[0], 1))
    scaler = MinMaxScaler()
    x_scaled = scaler.fit_transform(x)
    return x_scaled, y

# Create and compile the model
def create_model(input_shape):
    model = Sequential()
    model.add(LSTM(50, input_shape=input_shape, activation='relu'))
    model.add(Dense(1))
    model.compile(optimizer='adam', loss='mse')
    return model

# Train the model
def train_model(model, x_scaled, y, epochs=100, batch_size=32):
    model.fit(x_scaled, y, epochs=epochs, batch_size=batch_size, validation_split=0.1)

# Save the best model
def save_best_model(model, file_path):
    model.save(file_path)

# Load the best model and evaluate it
def load_and_evaluate(file_path):
    model = Sequential()
    model.load(file_path)
    model.compile(optimizer='adam', loss='mse')
    score = model.evaluate(x_test, y_test, verbose=0)
    print(f'Test loss: {score[0]}')

# Main
if __name__ == '__main__':
    # Load data
    x, y = load_data('data.nb')
    x_scaled, y = preprocess(x, y)

    # Create and train the model
    input_shape = (1, 1, 68)  # 70 numbers with 1 timestamp
    model = create_model(input_shape)
    train_model(model, x_scaled, y)

    # Save the best model
    save_best_model(model, 'best_model')

    # Load the best model and evaluate
    load_and_evaluate('best_model'). ok, but what if on the output data there isn't any values to correspond due to new data that comes in and no one knows? How would that be then?