Gowthamvemula commited on
Commit
5349083
·
verified ·
1 Parent(s): ad109f9

Update Home.py

Browse files
Files changed (1) hide show
  1. Home.py +351 -231
Home.py CHANGED
@@ -2,58 +2,32 @@ import streamlit as st
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
- import graphviz
6
  import time
7
- from sklearn.datasets import make_moons, make_circles, make_classification
8
- from sklearn.datasets import make_regression
9
-
10
- # Set Streamlit page title
11
- st.set_page_config(page_title="Neural Network Trainer", layout="wide")
12
-
13
- # ================= Session State for Training Controls =================
14
- if "epoch" not in st.session_state:
15
- st.session_state.epoch = 0
16
- if "running" not in st.session_state:
17
- st.session_state.running = False
18
-
19
- # ================= TRAINING CONTROL PANEL (Top) =================
20
- st.markdown("### Training Controls")
21
- col1, col2, col3, col4, col5, col6, col7, col8, col9 = st.columns(9)
22
-
23
- with col1:
24
- if st.button("↩️ Reset"):
25
- st.session_state.epoch = 0
26
- st.session_state.running = False
27
- with col2:
28
- if st.button("▶️ Train"):
29
- st.session_state.running = True
30
- with col3:
31
- if st.button("⏸️ Pause"):
32
- st.session_state.running = False
33
- with col4:
34
- activation = st.selectbox("Activation", ["ReLU", "Sigmoid", "Tanh", "LeakyReLU"])
35
- with col5:
36
- regularization = st.selectbox("Regularization", ["None", "L1", "L2"])
37
- with col6:
38
- reg_rate = st.selectbox("Regularization Rate", [0.0001, 0.001, 0.01, 0.1]) if regularization in ["L1", "L2"] else 0
39
- with col7:
40
- problem_type = st.selectbox("Problem Type", ["Classification", "Regression"])
41
- with col8:
42
- learning_rate = st.selectbox("Learning Rate", [0.0001, 0.001, 0.01, 0.03, 0.1])
43
- with col9:
44
- st.write(f"Epoch: {st.session_state.epoch}")
45
-
46
- # 🚀 Fix: Run training loop without breaking Streamlit
47
- if st.session_state.running:
48
- time.sleep(1) # Simulating training
49
- st.session_state.epoch += 1
50
 
51
- # ================= MAIN LAYOUT =================
52
- col_features, col_hidden, col_output = st.columns([2, 2, 2])
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- # ========== FEATURE SELECTION MOVED TO MIDDLE ==========
55
- with col_features:
56
- st.header("FEATURE SELECTION")
57
  feature_dict = {
58
  "X₁": st.checkbox("X₁", value=True),
59
  "X₂": st.checkbox("X₂", value=True),
@@ -61,207 +35,353 @@ with col_features:
61
  "X₂²": st.checkbox("X₂²"),
62
  "X₁X₂": st.checkbox("X₁X₂"),
63
  "sin(X₁)": st.checkbox("sin(X₁)"),
64
- "sin(X₂)": st.checkbox("sin(X₂)"),
65
  }
66
  selected_features = [f for f, v in feature_dict.items() if v]
67
 
68
- # ========== HIDDEN LAYERS PANEL (Middle) ========== #
69
- with col_hidden:
70
- st.header("HIDDEN LAYERS")
71
- hidden_layers = st.slider("Number of Hidden Layers", 1, 7, 2)
72
-
73
- neurons = []
74
- for i in range(hidden_layers):
75
- neurons.append(st.slider(f"Neurons in Layer {i+1}", 1, 20, 4))
76
-
77
- # ========== OUTPUT PANEL (Right) ========== #
78
- with col_output:
79
- st.header("OUTPUT")
80
- st.write("Test Loss: 0.501")
81
- st.write("Training Loss: 0.507")
82
-
83
- # Spiral Plot with Updated Color Palette
84
- x = np.linspace(-6, 6, 300)
85
- y = np.sin(x) + np.random.normal(0, 0.1, x.shape)
86
-
87
- fig, ax = plt.subplots()
88
- sns.scatterplot(x=x, y=y, hue=x, palette="plasma", ax=ax)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  st.pyplot(fig)
90
 
91
- show_test_data = st.checkbox("Show test data")
92
- discretize_output = st.checkbox("Discretize output")
93
-
94
-
95
-
96
- # Sidebar for dataset selection
97
- st.sidebar.header("Dataset Selection")
98
- data_type = st.sidebar.radio("Choose Data Type", ["Classification", "Regression"])
99
-
100
- # Generate classification data
101
- def generate_classification_data():
102
- st.sidebar.subheader("Classification Settings")
103
- dataset_type = st.sidebar.selectbox("Dataset Type", ["Moons", "Circles", "Classification"])
104
- noise = st.sidebar.slider("Noise Level", 0.0, 1.0, 0.2, step=0.05)
105
- samples = st.sidebar.slider("Number of Samples", 100, 1000, 500, step=50)
106
-
107
- if dataset_type == "Moons":
108
  X, y = make_moons(n_samples=samples, noise=noise)
109
- elif dataset_type == "Circles":
110
- X, y = make_circles(n_samples=samples, noise=noise, factor=0.5)
111
  else:
112
- X, y = make_classification(n_samples=samples, n_features=2, n_classes=2, n_clusters_per_class=1, flip_y=noise)
113
-
114
  return X, y
115
 
116
- # Generate regression data
117
- def generate_regression_data():
118
- st.sidebar.subheader("Regression Settings")
119
- samples = st.sidebar.slider("Number of Samples", 100, 1000, 500, step=50)
120
- noise = st.sidebar.slider("Noise Level", 0.0, 10.0, 2.0, step=0.5)
121
 
122
- X, y = make_regression(n_samples=samples, n_features=1, noise=noise)
123
- return X, y
 
 
 
 
 
 
 
 
124
 
125
- # Select dataset type
 
 
126
  if data_type == "Classification":
127
- X, y = generate_classification_data()
128
- cmap = "coolwarm"
129
- title = "Classification Data"
130
- is_classification = True
131
- else:
132
- X, y = generate_regression_data()
133
- cmap = "plasma"
134
- title = "Regression Data"
135
- is_classification = False
136
-
137
- # 🎯 Reduced Size of the Plot
138
- fig, ax = plt.subplots(figsize=(4, 2)) # Smaller size (width=4, height=2)
139
-
140
- if is_classification:
141
- scatter = ax.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap, edgecolors="white", alpha=0.8)
142
- ax.set_xlabel("Feature 1", fontsize=8)
143
- ax.set_ylabel("Feature 2", fontsize=8)
144
  else:
145
- scatter = ax.scatter(X[:, 0], y, c=y, cmap=cmap, edgecolors="white", alpha=0.8)
146
- sns.kdeplot(x=X[:, 0], y=y, fill=True, cmap=cmap, alpha=0.3, ax=ax)
147
- ax.set_xlabel("Feature 1", fontsize=8)
148
- ax.set_ylabel("Target", fontsize=8)
149
-
150
- ax.set_title(title, fontsize=10)
151
- ax.tick_params(axis='both', labelsize=7)
152
- ax.grid(True, linewidth=0.5)
153
-
154
- # Display in Streamlit
155
  st.pyplot(fig)
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
- # ================= NEURAL NETWORK VISUALIZATION =================
159
- def draw_neural_network():
160
- graph = graphviz.Digraph(engine="dot")
161
-
162
- # Input Layer (Features)
163
- input_nodes = []
164
- for feature in selected_features:
165
- graph.node(feature, feature, shape="circle", style="filled", fillcolor="lightblue", width="0.6", height="0.6")
166
- input_nodes.append(feature)
167
-
168
- # Hidden Layers
169
- prev_layer = input_nodes
170
- hidden_layers_nodes = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- for i, num_neurons in enumerate(neurons):
173
- layer_nodes = [f"H{i+1}_{j+1}" for j in range(num_neurons)]
174
- hidden_layers_nodes.append(layer_nodes)
175
 
176
- for node in layer_nodes:
177
- graph.node(node, node, shape="circle", style="filled", fillcolor="lightyellow", width="0.6", height="0.6")
178
 
179
- # Connect previous layer to this hidden layer
180
- for prev in prev_layer:
181
- for curr in layer_nodes:
182
- graph.edge(prev, curr)
183
 
184
- prev_layer = layer_nodes # Update previous layer for next iteration
185
 
186
- # Output Layer
187
- graph.node("Output", "Output", shape="circle", style="filled", fillcolor="lightgreen", width="0.6", height="0.6")
188
 
189
- # Connect last hidden layer to output
190
- for last_hidden in prev_layer:
191
- graph.edge(last_hidden, "Output")
192
-
193
- graph.attr(rankdir="LR") # Make it horizontal (Left to Right)
194
-
195
- return graph
196
-
197
- # =================== DISPLAY NEURAL NETWORK ===================
198
- st.graphviz_chart(draw_neural_network())
199
-
200
-
201
- # =================== DISPLAY DATA PLOT ===================
202
- st.sidebar.subheader("Dataset Visualization")
203
- fig, ax = plt.subplots()
204
- ax.scatter(X[:, 0], X[:, 1], c=y, cmap="plasma", edgecolors="k")
205
- st.sidebar.pyplot(fig)
206
- import streamlit as st
207
- import numpy as np
208
- import matplotlib.pyplot as plt
209
- import time
210
-
211
- # Initialize session state
212
- if "epoch" not in st.session_state:
213
- st.session_state.epoch = 0
214
- if "running" not in st.session_state:
215
- st.session_state.running = False
216
- if "loss_history" not in st.session_state:
217
- st.session_state.loss_history = []
218
-
219
- # Training controls
220
- col1, col2, col3 = st.columns(3)
221
- with col1:
222
- if st.button("Reset"):
223
- st.session_state.epoch = 0
224
- st.session_state.running = False
225
- st.session_state.loss_history = []
226
- with col2:
227
- if st.button("Train"):
228
- st.session_state.running = True
229
- with col3:
230
- if st.button("Pause"):
231
- st.session_state.running = False
232
-
233
- # Training loop simulation
234
- if st.session_state.running:
235
- for _ in range(10):
236
- time.sleep(0.5)
237
- st.session_state.epoch += 1
238
- simulated_loss = np.exp(-0.1 * st.session_state.epoch) + np.random.normal(0, 0.02)
239
- st.session_state.loss_history.append(simulated_loss)
240
-
241
- # Epoch vs Training Loss Plot (Smaller Size)
242
- st.header("Epoch vs Training Loss")
243
- fig, ax = plt.subplots(figsize=(4, 2)) # Reduce plot size (width=4, height=2)
244
- ax.plot(range(1, len(st.session_state.loss_history) + 1), st.session_state.loss_history, marker="o", linestyle="-", color="blue")
245
- ax.set_xlabel("Epoch")
246
- ax.set_ylabel("Training Loss")
247
- ax.set_title("Training Loss Over Epochs", fontsize=10)
248
- ax.tick_params(axis='both', labelsize=8)
249
- ax.grid(True, linewidth=0.5)
250
-
251
- st.pyplot(fig)
252
-
253
- # Display current epoch and training loss below the plot
254
- if st.session_state.loss_history:
255
- st.write(f"Epoch: {st.session_state.epoch}")
256
- st.write(f"Training Loss: {st.session_state.loss_history[-1]:.4f}")
257
-
258
-
259
- # Display current epoch and training loss below the plot
260
- if st.session_state.loss_history:
261
- st.write(f"Epoch: {st.session_state.epoch}")
262
- st.write(f"Training Loss: {st.session_state.loss_history[-1]:.4f}")
263
- # =================== TRAINING STATUS ===================
264
- if st.session_state.running:
265
- st.write("🚀 Training started...")
266
- elif not st.session_state.running and st.session_state.epoch > 0:
267
- st.write("⏸️ Training paused.")
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
 
5
  import time
6
+ from sklearn.datasets import make_moons, make_circles, make_classification, make_regression
7
+
8
+ # Set Streamlit page style
9
+ st.set_page_config(page_title="🔬 Neural Net Playground", layout="wide")
10
+ st.markdown("<style>.block-container {padding-top: 1rem;}</style>", unsafe_allow_html=True)
11
+
12
+ # ========== Initialize Session State ==========
13
+ if "epoch" not in st.session_state: st.session_state.epoch = 0
14
+ if "running" not in st.session_state: st.session_state.running = False
15
+ if "loss_history" not in st.session_state: st.session_state.loss_history = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ # ========== Title ==========
18
+ st.title("🧠 Neural Network Trainer")
19
+ st.markdown("Interactive trainer for basic neural network concepts.")
20
+
21
+ # ========== 3-COLUMN LAYOUT ==========
22
+ left, mid, right = st.columns([2, 3, 2])
23
+
24
+ # ========= Left: Dataset & Feature Controls =========
25
+ with left:
26
+ st.header("📊 Dataset & Features")
27
+ data_type = st.radio("Data Type", ["Classification", "Regression"])
28
+ noise = st.slider("Noise", 0.0, 1.0, 0.2, 0.05)
29
+ samples = st.slider("Samples", 100, 1000, 500, 50)
30
 
 
 
 
31
  feature_dict = {
32
  "X₁": st.checkbox("X₁", value=True),
33
  "X₂": st.checkbox("X₂", value=True),
 
35
  "X₂²": st.checkbox("X₂²"),
36
  "X₁X₂": st.checkbox("X₁X₂"),
37
  "sin(X₁)": st.checkbox("sin(X₁)"),
38
+ "sin(X₂)": st.checkbox("sin(X₂)")
39
  }
40
  selected_features = [f for f, v in feature_dict.items() if v]
41
 
42
+ # ========= Middle: Training Controls =========
43
+ with mid:
44
+ st.header("⚙️ Model Settings")
45
+ c1, c2, c3 = st.columns(3)
46
+ with c1:
47
+ activation = st.selectbox("Activation", ["ReLU", "Sigmoid", "Tanh"])
48
+ with c2:
49
+ regularization = st.selectbox("Regularization", ["None", "L1", "L2"])
50
+ with c3:
51
+ learning_rate = st.select_slider("Learning Rate", [0.0001, 0.001, 0.01, 0.03, 0.1], value=0.01)
52
+
53
+ reg_rate = st.slider("Reg. Rate", 0.0001, 0.1, 0.01) if regularization != "None" else 0
54
+ hidden_layers = st.slider("Hidden Layers", 1, 5, 2)
55
+ neurons = [st.slider(f"Neurons in Layer {i+1}", 2, 20, 4) for i in range(hidden_layers)]
56
+
57
+ st.subheader("Training Controls")
58
+ col_a, col_b, col_c = st.columns(3)
59
+ with col_a:
60
+ if st.button("🔄 Reset"):
61
+ st.session_state.epoch = 0
62
+ st.session_state.running = False
63
+ st.session_state.loss_history = []
64
+ with col_b:
65
+ if st.button("▶️ Train"):
66
+ st.session_state.running = True
67
+ with col_c:
68
+ if st.button("⏸️ Pause"):
69
+ st.session_state.running = False
70
+
71
+ # ========= Right: Metrics & Plot =========
72
+ with right:
73
+ st.header("📈 Live Metrics")
74
+ if st.session_state.loss_history:
75
+ st.metric("Epoch", st.session_state.epoch)
76
+ st.metric("Current Loss", f"{st.session_state.loss_history[-1]:.4f}")
77
+ else:
78
+ st.info("No training yet.")
79
+
80
+ st.subheader("Training Loss")
81
+ fig, ax = plt.subplots(figsize=(4, 2))
82
+ ax.plot(st.session_state.loss_history, color="royalblue", marker="o")
83
+ ax.set_xlabel("Epoch")
84
+ ax.set_ylabel("Loss")
85
+ ax.grid(True, linestyle="--", linewidth=0.5)
86
  st.pyplot(fig)
87
 
88
+ # ========== Dataset Generation ==========
89
+ def get_data():
90
+ if data_type == "Classification":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  X, y = make_moons(n_samples=samples, noise=noise)
 
 
92
  else:
93
+ X, y = make_regression(n_samples=samples, n_features=1, noise=noise*10)
 
94
  return X, y
95
 
96
+ X, y = get_data()
 
 
 
 
97
 
98
+ # ========== Training Loop Simulation ==========
99
+ if st.session_state.running:
100
+ progress = st.progress(0, text="Training in progress...")
101
+ for i in range(10):
102
+ time.sleep(0.1)
103
+ st.session_state.epoch += 1
104
+ loss = np.exp(-0.05 * st.session_state.epoch) + np.random.normal(0, 0.02)
105
+ st.session_state.loss_history.append(loss)
106
+ progress.progress((i+1)/10, text=f"Training... Epoch {st.session_state.epoch}")
107
+ progress.empty()
108
 
109
+ # ========== Dataset Plot ==========
110
+ st.subheader("🧪 Dataset Visualization")
111
+ fig, ax = plt.subplots()
112
  if data_type == "Classification":
113
+ scatter = ax.scatter(X[:, 0], X[:, 1], c=y, cmap="coolwarm", edgecolor="k")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  else:
115
+ ax.scatter(X[:, 0], y, c=y, cmap="plasma", edgecolor="k")
116
+ sns.kdeplot(x=X[:, 0], y=y, fill=True, cmap="plasma", ax=ax, alpha=0.3)
117
+ ax.set_title(f"{data_type} Dataset")
118
+ ax.grid(True)
 
 
 
 
 
 
119
  st.pyplot(fig)
120
 
121
+ # import streamlit as st
122
+ # import numpy as np
123
+ # import matplotlib.pyplot as plt
124
+ # import seaborn as sns
125
+ # import graphviz
126
+ # import time
127
+ # from sklearn.datasets import make_moons, make_circles, make_classification
128
+ # from sklearn.datasets import make_regression
129
+
130
+ # # Set Streamlit page title
131
+ # st.set_page_config(page_title="Neural Network Trainer", layout="wide")
132
+
133
+ # # ================= Session State for Training Controls =================
134
+ # if "epoch" not in st.session_state:
135
+ # st.session_state.epoch = 0
136
+ # if "running" not in st.session_state:
137
+ # st.session_state.running = False
138
+
139
+ # # ================= TRAINING CONTROL PANEL (Top) =================
140
+ # st.markdown("### Training Controls")
141
+ # col1, col2, col3, col4, col5, col6, col7, col8, col9 = st.columns(9)
142
+
143
+ # with col1:
144
+ # if st.button("↩️ Reset"):
145
+ # st.session_state.epoch = 0
146
+ # st.session_state.running = False
147
+ # with col2:
148
+ # if st.button("▶️ Train"):
149
+ # st.session_state.running = True
150
+ # with col3:
151
+ # if st.button("⏸️ Pause"):
152
+ # st.session_state.running = False
153
+ # with col4:
154
+ # activation = st.selectbox("Activation", ["ReLU", "Sigmoid", "Tanh", "LeakyReLU"])
155
+ # with col5:
156
+ # regularization = st.selectbox("Regularization", ["None", "L1", "L2"])
157
+ # with col6:
158
+ # reg_rate = st.selectbox("Regularization Rate", [0.0001, 0.001, 0.01, 0.1]) if regularization in ["L1", "L2"] else 0
159
+ # with col7:
160
+ # problem_type = st.selectbox("Problem Type", ["Classification", "Regression"])
161
+ # with col8:
162
+ # learning_rate = st.selectbox("Learning Rate", [0.0001, 0.001, 0.01, 0.03, 0.1])
163
+ # with col9:
164
+ # st.write(f"Epoch: {st.session_state.epoch}")
165
+
166
+ # # 🚀 Fix: Run training loop without breaking Streamlit
167
+ # if st.session_state.running:
168
+ # time.sleep(1) # Simulating training
169
+ # st.session_state.epoch += 1
170
+
171
+ # # ================= MAIN LAYOUT =================
172
+ # col_features, col_hidden, col_output = st.columns([2, 2, 2])
173
+
174
+ # # ========== FEATURE SELECTION MOVED TO MIDDLE ==========
175
+ # with col_features:
176
+ # st.header("FEATURE SELECTION")
177
+ # feature_dict = {
178
+ # "X₁": st.checkbox("X₁", value=True),
179
+ # "X₂": st.checkbox("X₂", value=True),
180
+ # "X₁²": st.checkbox("X₁²"),
181
+ # "X₂²": st.checkbox("X₂²"),
182
+ # "X₁X₂": st.checkbox("X₁X₂"),
183
+ # "sin(X₁)": st.checkbox("sin(X₁)"),
184
+ # "sin(X₂)": st.checkbox("sin(X₂)"),
185
+ # }
186
+ # selected_features = [f for f, v in feature_dict.items() if v]
187
+
188
+ # # ========== HIDDEN LAYERS PANEL (Middle) ========== #
189
+ # with col_hidden:
190
+ # st.header("HIDDEN LAYERS")
191
+ # hidden_layers = st.slider("Number of Hidden Layers", 1, 7, 2)
192
+
193
+ # neurons = []
194
+ # for i in range(hidden_layers):
195
+ # neurons.append(st.slider(f"Neurons in Layer {i+1}", 1, 20, 4))
196
+
197
+ # # ========== OUTPUT PANEL (Right) ========== #
198
+ # with col_output:
199
+ # st.header("OUTPUT")
200
+ # st.write("Test Loss: 0.501")
201
+ # st.write("Training Loss: 0.507")
202
+
203
+ # # Spiral Plot with Updated Color Palette
204
+ # x = np.linspace(-6, 6, 300)
205
+ # y = np.sin(x) + np.random.normal(0, 0.1, x.shape)
206
+
207
+ # fig, ax = plt.subplots()
208
+ # sns.scatterplot(x=x, y=y, hue=x, palette="plasma", ax=ax)
209
+ # st.pyplot(fig)
210
+
211
+ # show_test_data = st.checkbox("Show test data")
212
+ # discretize_output = st.checkbox("Discretize output")
213
 
214
+
215
+
216
+ # # Sidebar for dataset selection
217
+ # st.sidebar.header("Dataset Selection")
218
+ # data_type = st.sidebar.radio("Choose Data Type", ["Classification", "Regression"])
219
+
220
+ # # Generate classification data
221
+ # def generate_classification_data():
222
+ # st.sidebar.subheader("Classification Settings")
223
+ # dataset_type = st.sidebar.selectbox("Dataset Type", ["Moons", "Circles", "Classification"])
224
+ # noise = st.sidebar.slider("Noise Level", 0.0, 1.0, 0.2, step=0.05)
225
+ # samples = st.sidebar.slider("Number of Samples", 100, 1000, 500, step=50)
226
+
227
+ # if dataset_type == "Moons":
228
+ # X, y = make_moons(n_samples=samples, noise=noise)
229
+ # elif dataset_type == "Circles":
230
+ # X, y = make_circles(n_samples=samples, noise=noise, factor=0.5)
231
+ # else:
232
+ # X, y = make_classification(n_samples=samples, n_features=2, n_classes=2, n_clusters_per_class=1, flip_y=noise)
233
+
234
+ # return X, y
235
+
236
+ # # Generate regression data
237
+ # def generate_regression_data():
238
+ # st.sidebar.subheader("Regression Settings")
239
+ # samples = st.sidebar.slider("Number of Samples", 100, 1000, 500, step=50)
240
+ # noise = st.sidebar.slider("Noise Level", 0.0, 10.0, 2.0, step=0.5)
241
+
242
+ # X, y = make_regression(n_samples=samples, n_features=1, noise=noise)
243
+ # return X, y
244
+
245
+ # # Select dataset type
246
+ # if data_type == "Classification":
247
+ # X, y = generate_classification_data()
248
+ # cmap = "coolwarm"
249
+ # title = "Classification Data"
250
+ # is_classification = True
251
+ # else:
252
+ # X, y = generate_regression_data()
253
+ # cmap = "plasma"
254
+ # title = "Regression Data"
255
+ # is_classification = False
256
+
257
+ # # 🎯 Reduced Size of the Plot
258
+ # fig, ax = plt.subplots(figsize=(4, 2)) # Smaller size (width=4, height=2)
259
+
260
+ # if is_classification:
261
+ # scatter = ax.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap, edgecolors="white", alpha=0.8)
262
+ # ax.set_xlabel("Feature 1", fontsize=8)
263
+ # ax.set_ylabel("Feature 2", fontsize=8)
264
+ # else:
265
+ # scatter = ax.scatter(X[:, 0], y, c=y, cmap=cmap, edgecolors="white", alpha=0.8)
266
+ # sns.kdeplot(x=X[:, 0], y=y, fill=True, cmap=cmap, alpha=0.3, ax=ax)
267
+ # ax.set_xlabel("Feature 1", fontsize=8)
268
+ # ax.set_ylabel("Target", fontsize=8)
269
+
270
+ # ax.set_title(title, fontsize=10)
271
+ # ax.tick_params(axis='both', labelsize=7)
272
+ # ax.grid(True, linewidth=0.5)
273
+
274
+ # # Display in Streamlit
275
+ # st.pyplot(fig)
276
+
277
+
278
+ # # ================= NEURAL NETWORK VISUALIZATION =================
279
+ # def draw_neural_network():
280
+ # graph = graphviz.Digraph(engine="dot")
281
+
282
+ # # Input Layer (Features)
283
+ # input_nodes = []
284
+ # for feature in selected_features:
285
+ # graph.node(feature, feature, shape="circle", style="filled", fillcolor="lightblue", width="0.6", height="0.6")
286
+ # input_nodes.append(feature)
287
+
288
+ # # Hidden Layers
289
+ # prev_layer = input_nodes
290
+ # hidden_layers_nodes = []
291
 
292
+ # for i, num_neurons in enumerate(neurons):
293
+ # layer_nodes = [f"H{i+1}_{j+1}" for j in range(num_neurons)]
294
+ # hidden_layers_nodes.append(layer_nodes)
295
 
296
+ # for node in layer_nodes:
297
+ # graph.node(node, node, shape="circle", style="filled", fillcolor="lightyellow", width="0.6", height="0.6")
298
 
299
+ # # Connect previous layer to this hidden layer
300
+ # for prev in prev_layer:
301
+ # for curr in layer_nodes:
302
+ # graph.edge(prev, curr)
303
 
304
+ # prev_layer = layer_nodes # Update previous layer for next iteration
305
 
306
+ # # Output Layer
307
+ # graph.node("Output", "Output", shape="circle", style="filled", fillcolor="lightgreen", width="0.6", height="0.6")
308
 
309
+ # # Connect last hidden layer to output
310
+ # for last_hidden in prev_layer:
311
+ # graph.edge(last_hidden, "Output")
312
+
313
+ # graph.attr(rankdir="LR") # Make it horizontal (Left to Right)
314
+
315
+ # return graph
316
+
317
+ # # =================== DISPLAY NEURAL NETWORK ===================
318
+ # st.graphviz_chart(draw_neural_network())
319
+
320
+
321
+ # # =================== DISPLAY DATA PLOT ===================
322
+ # st.sidebar.subheader("Dataset Visualization")
323
+ # fig, ax = plt.subplots()
324
+ # ax.scatter(X[:, 0], X[:, 1], c=y, cmap="plasma", edgecolors="k")
325
+ # st.sidebar.pyplot(fig)
326
+ # import streamlit as st
327
+ # import numpy as np
328
+ # import matplotlib.pyplot as plt
329
+ # import time
330
+
331
+ # # Initialize session state
332
+ # if "epoch" not in st.session_state:
333
+ # st.session_state.epoch = 0
334
+ # if "running" not in st.session_state:
335
+ # st.session_state.running = False
336
+ # if "loss_history" not in st.session_state:
337
+ # st.session_state.loss_history = []
338
+
339
+ # # Training controls
340
+ # col1, col2, col3 = st.columns(3)
341
+ # with col1:
342
+ # if st.button("Reset"):
343
+ # st.session_state.epoch = 0
344
+ # st.session_state.running = False
345
+ # st.session_state.loss_history = []
346
+ # with col2:
347
+ # if st.button("Train"):
348
+ # st.session_state.running = True
349
+ # with col3:
350
+ # if st.button("Pause"):
351
+ # st.session_state.running = False
352
+
353
+ # # Training loop simulation
354
+ # if st.session_state.running:
355
+ # for _ in range(10):
356
+ # time.sleep(0.5)
357
+ # st.session_state.epoch += 1
358
+ # simulated_loss = np.exp(-0.1 * st.session_state.epoch) + np.random.normal(0, 0.02)
359
+ # st.session_state.loss_history.append(simulated_loss)
360
+
361
+ # # Epoch vs Training Loss Plot (Smaller Size)
362
+ # st.header("Epoch vs Training Loss")
363
+ # fig, ax = plt.subplots(figsize=(4, 2)) # Reduce plot size (width=4, height=2)
364
+ # ax.plot(range(1, len(st.session_state.loss_history) + 1), st.session_state.loss_history, marker="o", linestyle="-", color="blue")
365
+ # ax.set_xlabel("Epoch")
366
+ # ax.set_ylabel("Training Loss")
367
+ # ax.set_title("Training Loss Over Epochs", fontsize=10)
368
+ # ax.tick_params(axis='both', labelsize=8)
369
+ # ax.grid(True, linewidth=0.5)
370
+
371
+ # st.pyplot(fig)
372
+
373
+ # # Display current epoch and training loss below the plot
374
+ # if st.session_state.loss_history:
375
+ # st.write(f"Epoch: {st.session_state.epoch}")
376
+ # st.write(f"Training Loss: {st.session_state.loss_history[-1]:.4f}")
377
+
378
+
379
+ # # Display current epoch and training loss below the plot
380
+ # if st.session_state.loss_history:
381
+ # st.write(f"Epoch: {st.session_state.epoch}")
382
+ # st.write(f"Training Loss: {st.session_state.loss_history[-1]:.4f}")
383
+ # # =================== TRAINING STATUS ===================
384
+ # if st.session_state.running:
385
+ # st.write("🚀 Training started...")
386
+ # elif not st.session_state.running and st.session_state.epoch > 0:
387
+ # st.write("⏸️ Training paused.")