Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error with output
#1
I have the following code, throwing the error: can some help out with the executable code for the same
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Flatten
from sklearn.model_selection import train_test_split

# Function to generate synthetic BZ reaction data
def generate_bz_data(num_samples, spatial_dim, temporal_dim):
    data = np.random.rand(num_samples, spatial_dim, temporal_dim, 1)
    labels = np.random.randint(0, 2, size=(num_samples, spatial_dim, temporal_dim, 1))
    return data, labels

# Generate synthetic BZ reaction data
num_samples = 1000
spatial_dim = 32
temporal_dim = 20
X, y = generate_bz_data(num_samples, spatial_dim, temporal_dim)

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Build an RNN model
model = Sequential()
model.add(LSTM(50, input_shape=(spatial_dim, temporal_dim, 1), return_sequences=True))
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))

# Compile the model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# Train the model
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_data=(X_test, y_test))

# Generate new spatiotemporal patterns using the trained model
new_data = np.random.rand(5, spatial_dim, temporal_dim, 1)
generated_patterns = model.predict(new_data)

# Visualize the generated patterns
fig, axes = plt.subplots(1, 5, figsize=(15, 3))
for i in range(5):
    axes[i].imshow(np.squeeze(new_data[i, :, :, :]), cmap='viridis')
    axes[i].set_title(f'Generated Pattern {i+1}')
    axes[i].axis('off')

plt.show()
Yoriz write Nov-27-2023, 05:34 PM:
Please post all code, output and errors (in its entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
What is the error?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] No Error, and No Output vishal2894 1 1,720 Jul-02-2019, 03:20 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020