# Tokenize and pad the text data
tokenizer = Tokenizer()
tokenizer.fit_on_texts(df['Event'])
sequences = tokenizer.texts_to_sequences(df['Event'])
max_length = max([len(seq) for seq in sequences])
sequences_padded = pad_sequences(sequences, maxlen=max_length, padding='post')

# Encode the dates
encoder = LabelEncoder()
df['Date'] = encoder.fit_transform(df['Date'])


# Assuming 'Date' is the name of your column with date information
df['Date'] = pd.to_datetime(df['Date'])

# Assuming `df['Date']` is in datetime format
df['Year'] = df['Date'].dt.year
df['Month'] = df['Date'].dt.month
df['Day'] = df['Date'].dt.day

# Combine these into a NumPy array or DataFrame
X_dates = df[['Year', 'Month', 'Day']].values


from sklearn.preprocessing import OneHotEncoder

encoder = OneHotEncoder(sparse=False)
y_encoded = encoder.fit_transform(df[['Event']])


from sklearn.model_selection import train_test_split

# Split your data accordingly
X_text_train, X_text_test, X_date_train, X_date_test, y_train, y_test = train_test_split(
    sequences_padded, X_dates, y_encoded, test_size=0.2, random_state=42)


from tensorflow.keras.layers import Input, Embedding, LSTM, Dense, Concatenate
from tensorflow.keras.models import Model

# Assuming vocab_size, max_length, and num_classes are correctly defined
vocab_size = len(tokenizer.word_index) + 1  # Add 1 for padding token
max_length = max([len(x) for x in sequences])  # Maximum sequence length
num_classes = y_encoded.shape[1]  # Number of unique classes

# Text Input Model
text_input = Input(shape=(max_length,), dtype='int32', name='text_input')
text_embedding = Embedding(input_dim=vocab_size, output_dim=50, name='text_embedding')(text_input)
text_lstm = LSTM(50, name='text_lstm')(text_embedding)

# Date Input Model
date_input = Input(shape=(3,), name='date_input')  # Assuming [Year, Month, Day] format
date_dense = Dense(50, activation='relu', name='date_dense')(date_input)

# Concatenate the outputs of the two models
concatenated = Concatenate()([text_lstm, date_dense])
output_layer = Dense(num_classes, activation='softmax')(concatenated)

# Combined Model
combined_model = Model(inputs=[text_input, date_input], outputs=output_layer)


### Step 2: Compile the Model

combined_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

import numpy as np

# Example `y_train` array
# y_train = np.array([...])

# Calculate the occurrences of each class
class_weights = {}
labels, counts = np.unique(y_train, return_counts=True)

# Calculate the weight for each class
for label, count in zip(labels, counts):
    class_weights[label] = len(y_train) / (len(labels) * count)

print(class_weights)

from tensorflow.keras.layers import Input, Embedding, LSTM, Dense, Concatenate
from tensorflow.keras.models import Model

# Assuming vocab_size, max_length, and num_classes are correctly defined
vocab_size = len(tokenizer.word_index) + 1  # Add 1 for padding token
max_length = max([len(x) for x in sequences])  # Maximum sequence length
num_classes = y_encoded.shape[1]  # Number of unique classes

# Date Input Model
date_input = Input(shape=(3,), name='date_input')  # Assuming [Year, Month, Day] format
date_dense = Dense(50, activation='relu', name='date_dense')(date_input)

# Text Output Model
text_output = Input(shape=(max_length,), dtype='int32', name='text_output')
text_embedding = Embedding(input_dim=vocab_size, output_dim=50, name='text_embedding')(text_output)
text_lstm = LSTM(50, name='text_lstm')(text_embedding)

# Concatenate the outputs of the two models
concatenated = Concatenate()([date_dense, text_lstm])
output_layer = Dense(num_classes, activation='softmax')(concatenated)

# Combined Model
combined_model = Model(inputs=[date_input, text_output], outputs=output_layer)

### Step 2: Compile the Model

combined_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

### Step 3: Train the Model

# Ensure X_date_train, X_text_train, and y_train are correctly defined and prepared
history = combined_model.fit(
    [X_date_train, X_text_train], y_train,
    epochs=200,  # Adjust as necessary
    batch_size=32,  # Adjust as necessary
    validation_split=0.2,
    class_weight=class_weights# Adjust as necessary
)


convert code into time series analysis