You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Add detailed comments to model training notebook
Added comprehensive comments explaining the CNN architecture, model compilation, training process, evaluation, and visualization steps to improve code documentation.
"source": "# Compile the CNN model\n# Adam optimizer: adaptive learning rate optimization algorithm\n# sparse_categorical_crossentropy: loss function for multi-class classification with integer labels\n# accuracy: metric to monitor during training\nmodel.compile(optimizer = 'adam', loss='sparse_categorical_crossentropy', metrics = ['accuracy'])"
167
186
},
168
187
{
169
188
"cell_type": "code",
@@ -173,92 +192,63 @@
173
192
"scrolled": true
174
193
},
175
194
"outputs": [],
176
-
"source": [
177
-
"hist = model.fit(X, y, epochs=10, validation_split=0.2)"
178
-
]
195
+
"source": "# Train the model\n# epochs=10: train for 10 complete passes through the dataset\n# validation_split=0.2: use 20% of data for validation during training\nhist = model.fit(X, y, epochs=10, validation_split=0.2)"
179
196
},
180
197
{
181
198
"cell_type": "code",
182
199
"execution_count": null,
183
200
"id": "cc34347a",
184
201
"metadata": {},
185
202
"outputs": [],
186
-
"source": [
187
-
"model.summary()"
188
-
]
203
+
"source": "# Display model architecture summary\n# Shows layers, output shapes, and trainable parameters\nmodel.summary()"
189
204
},
190
205
{
191
206
"cell_type": "code",
192
207
"execution_count": null,
193
208
"id": "1f65bfca",
194
209
"metadata": {},
195
210
"outputs": [],
196
-
"source": [
197
-
"#to know accuracy of model\n",
198
-
"scores = model.evaluate(X,y,verbose=0)\n",
199
-
"print(\"Accuracy: %.2f%%\" % (scores[1]*100))"
200
-
]
211
+
"source": "# Evaluate model accuracy on the training data\nscores = model.evaluate(X,y,verbose=0)\nprint(\"Accuracy: %.2f%%\" % (scores[1]*100))"
201
212
},
202
213
{
203
214
"cell_type": "code",
204
215
"execution_count": null,
205
216
"id": "582c9ac3",
206
217
"metadata": {},
207
218
"outputs": [],
208
-
"source": [
209
-
"X.shape"
210
-
]
219
+
"source": "# Verify the shape of features array\nX.shape"
211
220
},
212
221
{
213
222
"cell_type": "code",
214
223
"execution_count": null,
215
224
"id": "466b56d3",
216
225
"metadata": {},
217
226
"outputs": [],
218
-
"source": [
219
-
"import matplotlib.pyplot as plt"
220
-
]
227
+
"source": "# Import matplotlib for visualizing training metrics\nimport matplotlib.pyplot as plt"
"source": "# Plot training and validation loss over epochs\nfig = plt.figure()\nplt.plot(hist.history['loss'],color='teal',label='loss') # Training loss\nplt.plot(hist.history['val_loss'],color='orange',label='val_loss') # Validation loss\nplt.suptitle('Loss',fontsize=20)\nplt.legend(loc=\"upper left\")\nplt.show"
"source": "# Plot training and validation accuracy over epochs\nfig = plt.figure()\nplt.plot(hist.history['accuracy'],color='teal',label='accuracy') # Training accuracy\nplt.plot(hist.history['val_accuracy'],color='orange',label='val_accuracy') # Validation accuracy\nplt.suptitle('Accuracy',fontsize=20)\nplt.legend(loc=\"upper left\")\nplt.show"
251
244
},
252
245
{
253
246
"cell_type": "code",
254
247
"execution_count": null,
255
248
"id": "9418fe74",
256
249
"metadata": {},
257
250
"outputs": [],
258
-
"source": [
259
-
"# save the model\n",
260
-
"model.save('3-class-improved.h5')"
261
-
]
251
+
"source": "# Save the trained model to disk\n# Saves model architecture, weights, and optimizer state\nmodel.save('3-class-improved.h5')"
0 commit comments