Adityaganesh commited on
Commit
300aab5
·
verified ·
1 Parent(s): e466263

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -39
app.py CHANGED
@@ -9,7 +9,7 @@ from sklearn.model_selection import train_test_split
9
  from sklearn.preprocessing import StandardScaler
10
  from sklearn.utils import shuffle
11
 
12
- # Custom CSS for sidebar
13
  st.markdown("""
14
  <style>
15
  .sidebar .css-12oz5g7 {
@@ -40,7 +40,7 @@ st.markdown("""
40
  </style>
41
  """, unsafe_allow_html=True)
42
 
43
- # Helper Functions
44
  def draw_neural_network(model):
45
  G = nx.DiGraph()
46
  pos = {}
@@ -127,6 +127,23 @@ def plot_learning_curves(history):
127
  plt.legend()
128
  st.pyplot(plt)
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  def generate_dataset(name):
131
  if name == "Circles":
132
  return make_circles(n_samples=1000, noise=0.1, factor=0.5)
@@ -149,32 +166,11 @@ def generate_dataset(name):
149
  y[ix] = j
150
  return shuffle(X, y)
151
 
152
- # App Title
153
- st.title("🧠 Neural Network Playground")
154
-
155
- # Sidebar inputs
156
- task_type = st.selectbox("Task Type", ["Classification", "Regression"])
157
- dataset = st.selectbox("Choose Dataset", ["Circles", "Exclusive OR", "Gaussian", "Spiral"])
158
- epochs = st.slider("Epochs", 1, 200, 50)
159
-
160
- col1, col2, col3 = st.columns(3)
161
- with col1:
162
- learning_rate = st.slider("Learning Rate", 0.001, 1.0, 0.03, 0.001)
163
- with col2:
164
- hidden_layers = st.slider("Hidden Layers", 1, 5, 3)
165
- neuron_counts = [st.slider(f"Neurons in Layer {i+1}", 1, 20, 5) for i in range(hidden_layers)]
166
- with col3:
167
- activation = st.selectbox("Activation", ["relu", "sigmoid", "tanh", "linear"])
168
- regularization = st.selectbox("Regularization", ["None", "L1", "L2"])
169
- reg_rate = st.slider("Reg. Rate", 0.0, 0.1, 0.01, 0.001) if regularization != "None" else 0.0
170
-
171
- # Data preparation
172
  X, y = generate_dataset(dataset)
173
  scaler = StandardScaler()
174
  X = scaler.fit_transform(X)
175
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
176
 
177
- # Model building
178
  model = keras.Sequential()
179
  first = True
180
  for count in neuron_counts:
@@ -200,26 +196,19 @@ else:
200
  model.compile(optimizer=keras.optimizers.Adam(learning_rate), loss=loss, metrics=metrics)
201
  history = model.fit(X_train, y_train, epochs=epochs, batch_size=32, verbose=0, validation_split=0.2)
202
 
203
- # Visualization layout
204
- st.subheader("Visualizations")
205
- left_col, center_col, _ = st.columns([2, 2, 1])
206
- with left_col:
207
- if task_type == "Classification":
208
- st.markdown("### Decision Boundary")
209
- plot_decision_boundary(X, y, model)
210
- else:
211
- st.markdown("### Regression Surface")
212
- plot_regression_surface(X, y, model)
213
 
214
- with center_col:
215
- st.markdown("### Neural Network Architecture")
216
- draw_neural_network(model)
 
 
 
217
 
218
- # Learning Curves
219
  st.subheader("Learning Curves")
220
  plot_learning_curves(history)
221
 
222
- # Show Model Summary
223
  if st.checkbox("Show Model Summary"):
224
  st.subheader("Model Summary")
225
- model.summary(print_fn=lambda x: st.text(x))
 
9
  from sklearn.preprocessing import StandardScaler
10
  from sklearn.utils import shuffle
11
 
12
+ # Custom CSS
13
  st.markdown("""
14
  <style>
15
  .sidebar .css-12oz5g7 {
 
40
  </style>
41
  """, unsafe_allow_html=True)
42
 
43
+ # Helper functions
44
  def draw_neural_network(model):
45
  G = nx.DiGraph()
46
  pos = {}
 
127
  plt.legend()
128
  st.pyplot(plt)
129
 
130
+ st.title("Neural Network Playground")
131
+
132
+ task_type = st.selectbox("Task Type", ["Classification", "Regression"])
133
+ dataset = st.selectbox("Choose Dataset", ["Circles", "Exclusive OR", "Gaussian", "Spiral"])
134
+ epochs = st.slider("Epochs", 1, 200, 50)
135
+
136
+ col1, col2, col3 = st.columns(3)
137
+ with col1:
138
+ learning_rate = st.slider("Learning Rate", 0.001, 1.0, 0.03, 0.001)
139
+ with col2:
140
+ hidden_layers = st.slider("Hidden Layers", 1, 5, 3)
141
+ neuron_counts = [st.slider(f"Neurons in Layer {i+1}", 1, 20, 5) for i in range(hidden_layers)]
142
+ with col3:
143
+ activation = st.selectbox("Activation", ["relu", "sigmoid", "tanh", "linear"])
144
+ regularization = st.selectbox("Regularization", ["None", "L1", "L2"])
145
+ reg_rate = st.slider("Reg. Rate", 0.0, 0.1, 0.01, 0.001) if regularization != "None" else 0.0
146
+
147
  def generate_dataset(name):
148
  if name == "Circles":
149
  return make_circles(n_samples=1000, noise=0.1, factor=0.5)
 
166
  y[ix] = j
167
  return shuffle(X, y)
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  X, y = generate_dataset(dataset)
170
  scaler = StandardScaler()
171
  X = scaler.fit_transform(X)
172
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
173
 
 
174
  model = keras.Sequential()
175
  first = True
176
  for count in neuron_counts:
 
196
  model.compile(optimizer=keras.optimizers.Adam(learning_rate), loss=loss, metrics=metrics)
197
  history = model.fit(X_train, y_train, epochs=epochs, batch_size=32, verbose=0, validation_split=0.2)
198
 
199
+ st.subheader("Network Structure")
200
+ draw_neural_network(model)
 
 
 
 
 
 
 
 
201
 
202
+ if task_type == "Classification":
203
+ st.subheader("Decision Boundary")
204
+ plot_decision_boundary(X, y, model)
205
+ else:
206
+ st.subheader("Regression Surface")
207
+ plot_regression_surface(X, y, model)
208
 
 
209
  st.subheader("Learning Curves")
210
  plot_learning_curves(history)
211
 
 
212
  if st.checkbox("Show Model Summary"):
213
  st.subheader("Model Summary")
214
+ model.summary(print_fn=lambda x: st.text(x))