Skip to content

Commit e096359

Browse files
author
M.Notter
committed
Finalized ML/DL blog post update
1 parent 37ae9a1 commit e096359

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

_posts/2023-10-23-01_scikit_simple.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ result_table = df_res.pivot(
225225
)
226226
sns.heatmap(100 * result_table, annot=True, fmt='.2f', square=True, cbar=False)
227227
plt.title("RF Accuracy on validation set, based on model hyper-parameter")
228-
plt.savefig('../assets/ex_plots/01_scikit_rf_heatmap.png', bbox_inches='tight', dpi=300)
228+
plt.savefig('01_scikit_rf_heatmap.png', bbox_inches='tight', dpi=300)
229229
plt.close()
230230
```
231231

@@ -309,7 +309,7 @@ result_table = df_res.pivot(
309309
)
310310
sns.heatmap(100 * result_table, annot=True, fmt='.2f', square=True)
311311
plt.title("SVM Accuracy on validation set, based on model hyper-parameter")
312-
plt.savefig('../assets/ex_plots/01_scikit_svm_heatmap.png', bbox_inches='tight', dpi=300)
312+
plt.savefig('01_scikit_svm_heatmap.png', bbox_inches='tight', dpi=300)
313313
plt.close()
314314
```
315315

@@ -368,7 +368,7 @@ cm = confusion_matrix(y_te, y_pred)
368368
sns.heatmap(pd.DataFrame(cm), annot=True, cbar=False, square=True)
369369
plt.xlabel("Predicted Class")
370370
plt.ylabel("True Class")
371-
plt.savefig('../assets/ex_plots/01_scikit_confusion_matrix.png', bbox_inches='tight', dpi=300)
371+
plt.savefig('01_scikit_confusion_matrix.png', bbox_inches='tight', dpi=300)
372372
plt.close()
373373
```
374374

@@ -398,7 +398,7 @@ feature_importance_image = feat_import.reshape(8, 8)
398398
plt.figure(figsize=(5, 5))
399399
plt.imshow(feature_importance_image)
400400
plt.title("RF Feature Importance")
401-
plt.savefig('../assets/ex_plots/01_scikit_feature_importance.png', bbox_inches='tight', dpi=300)
401+
plt.savefig('01_scikit_feature_importance.png', bbox_inches='tight', dpi=300)
402402
plt.close()
403403
```
404404

@@ -426,7 +426,7 @@ _, axes = plt.subplots(nrows=3, ncols=20, figsize=(9, 1.5))
426426
for ax, idx in zip(axes.ravel(), np.argsort(target_prob)[::-1]):
427427
ax.imshow(X_te[idx].reshape(8, 8), cmap=plt.cm.gray_r, interpolation='nearest')
428428
ax.set_axis_off()
429-
plt.savefig('../assets/ex_plots/01_scikit_confident_predictions.png', bbox_inches='tight', dpi=300)
429+
plt.savefig('01_scikit_confident_predictions.png', bbox_inches='tight', dpi=300)
430430
plt.close()
431431
```
432432

@@ -443,7 +443,7 @@ _, axes = plt.subplots(nrows=3, ncols=20, figsize=(9, 1.5))
443443
for ax, idx in zip(axes.ravel(), np.argsort(target_prob)):
444444
ax.imshow(X_te[idx].reshape(8, 8), cmap=plt.cm.gray_r, interpolation='nearest')
445445
ax.set_axis_off()
446-
plt.savefig('../assets/ex_plots/01_scikit_uncertain_predictions.png', bbox_inches='tight', dpi=300)
446+
plt.savefig('01_scikit_uncertain_predictions.png', bbox_inches='tight', dpi=300)
447447
plt.close()
448448
```
449449

_posts/2023-10-23-03_scikit_advanced.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ Prediction accuracy on test data: {score_te*100:.2f}%"
406406
)
407407
```
408408

409+
Prediction accuracy on train data: 7.08%
410+
Prediction accuracy on test data: 9.09%
411+
409412
Let's interpret these regression metrics in practical terms:
410413
- **Train Error**: On average, predictions deviate by about 7-8% from true house prices
411414
- For a $300,000 house, this means predictions are typically within ±$21,000-24,000

_posts/2023-10-23-04_tensorflow_advanced.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,10 @@ df.head()
6262

6363
Shape of dataset: (4177, 11)
6464

65-
|:--------:|:----------:|:--------:|:--------------:|:----------------:|:----------------:|:--------------:|:-------:|:-------:|:-------:|:-------:|
66-
| Length | Diameter | Height | Whole weight | Shucked weight | Viscera weight | Shell weight | Rings | Sex_F | Sex_I | Sex_M |
67-
|:--------:|:----------:|:--------:|:--------------:|:----------------:|:----------------:|:--------------:|:-------:|:-------:|:-------:|:-------:|
68-
| 0.455 | 0.365 | 0.095 | 0.514 | 0.2245 | 0.101 | 0.15 | 15 | 0 | 0 | 1 |
69-
| 0.35 | 0.265 | 0.09 | 0.2255 | 0.0995 | 0.0485 | 0.07 | 7 | 0 | 0 | 1 |
70-
| 0.53 | 0.42 | 0.135 | 0.677 | 0.2565 | 0.1415 | 0.21 | 9 | 1 | 0 | 0 |
71-
| 0.44 | 0.365 | 0.125 | 0.516 | 0.2155 | 0.114 | 0.155 | 10 | 0 | 0 | 1 |
72-
| 0.33 | 0.255 | 0.08 | 0.205 | 0.0895 | 0.0395 | 0.055 | 7 | 0 | 1 | 0 |
73-
74-
<br>
65+
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/ex_plots/04_tensorflow_dataset_table.png" data-zoomable width=800px style="padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px">
66+
<div class="caption">
67+
Figure 1: Overview of the abalone dataset.
68+
</div>
7569

7670
Next, let's split the dataset into a train and test set.
7771

@@ -309,7 +303,7 @@ plot_history(history_file='history_log.csv', title="Training overview")
309303
```
310304
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/ex_plots/04_tensorflow_training_history.png" data-zoomable width=800px style="padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px">
311305
<div class="caption">
312-
Figure 1: Training progress showing loss and Mean Absolute Error (MAE) metrics over epochs. The logarithmic scale helps visualize improvements across different orders of magnitude.
306+
Figure 2: Training progress showing loss and Mean Absolute Error (MAE) metrics over epochs. The logarithmic scale helps visualize improvements across different orders of magnitude.
313307
</div>
314308

315309
## Analyzing Model Performance
@@ -582,28 +576,38 @@ for gixd in grid_idx:
582576
print(f"\tModel Parameters: {model.count_params()}\n\n")
583577
```
584578

585-
Exploring: {'use_batch': False, 'optimizers': 'sgd', 'learning_rate': 0.0001, 'kernel_regularizer': None, 'kernel_init': 'glorot_uniform', 'hidden': [8], 'dropout_rate': 0, 'batch_size': 128, 'activation': 'selu'}
579+
Exploring: {'use_batch': False, 'optimizers': 'sgd', 'learning_rate': 0.0001,
580+
'kernel_regularizer': None, 'kernel_init': 'glorot_uniform', 'hidden': [8],
581+
'dropout_rate': 0, 'batch_size': 128, 'activation': 'selu'}
586582
Train - Loss: 5.294 | MAE: 1.643
587583
Test - Loss: 7.148 | MAE: 1.807
588584
Model Parameters: 118
589585

590-
Exploring: {'use_batch': False, 'optimizers': 'sgd', 'learning_rate': 0.001, 'kernel_regularizer': None, 'kernel_init': 'glorot_uniform', 'hidden': [8, 4], 'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'tanh'}
586+
Exploring: {'use_batch': False, 'optimizers': 'sgd', 'learning_rate': 0.001,
587+
'kernel_regularizer': None, 'kernel_init': 'glorot_uniform', 'hidden': [8, 4],
588+
'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'tanh'}
591589
Train - Loss: 5.290 | MAE: 1.583
592590
Test - Loss: 6.250 | MAE: 1.730
593591
Model Parameters: 150
594592

595-
Exploring: {'use_batch': True, 'optimizers': 'sgd', 'learning_rate': 0.0001, 'kernel_regularizer': None, 'kernel_init': 'uniform', 'hidden': [8, 4], 'dropout_rate': 0.5, 'batch_size': 32, 'activation': 'relu'}
593+
Exploring: {'use_batch': True, 'optimizers': 'sgd', 'learning_rate': 0.0001,
594+
'kernel_regularizer': None, 'kernel_init': 'uniform', 'hidden': [8, 4],
595+
'dropout_rate': 0.5, 'batch_size': 32, 'activation': 'relu'}
596596
Epoch 195: early stopping
597597
Train - Loss: 8.660 | MAE: 2.050
598598
Test - Loss: 10.039 | MAE: 2.144
599599
Model Parameters: 222
600600

601-
Exploring: {'use_batch': True, 'optimizers': 'rmsprop', 'learning_rate': 0.0001, 'kernel_regularizer': None, 'kernel_init': 'he_uniform', 'hidden': [8, 16, 8], 'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'tanh'}
601+
Exploring: {'use_batch': True, 'optimizers': 'rmsprop', 'learning_rate': 0.0001,
602+
'kernel_regularizer': None, 'kernel_init': 'he_uniform', 'hidden': [8, 16, 8],
603+
'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'tanh'}
602604
Train - Loss: 24.535 | MAE: 3.957
603605
Test - Loss: 26.605 | MAE: 4.079
604606
Model Parameters: 534
605607

606-
Exploring: {'use_batch': False, 'optimizers': 'adam', 'learning_rate': 0.0001, 'kernel_regularizer': 'l2', 'kernel_init': 'glorot_uniform', 'hidden': [8, 16, 8], 'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'selu'}
608+
Exploring: {'use_batch': False, 'optimizers': 'adam', 'learning_rate': 0.0001,
609+
'kernel_regularizer': 'l2', 'kernel_init': 'glorot_uniform', 'hidden': [8, 16, 8],
610+
'dropout_rate': 0.5, 'batch_size': 128, 'activation': 'selu'}
607611
Train - Loss: 6.947 | MAE: 1.715
608612
Test - Loss: 8.042 | MAE: 1.851
609613
Model Parameters: 398
@@ -643,16 +647,10 @@ results = pd.concat(results).reset_index(drop=True).sort_values('loss_te')
643647
results
644648
```
645649

646-
|:-----------:|:------------:|:---------------:|:--------------------:|:--------------:|:----------:|:--------------:|:------------:|:------------:|:---------:|:--------:|:---------:|:--------:|:-----:|
647-
| use_batch | optimizers | learning_rate | kernel_regularizer | kernel_init | hidden | dropout_rate | batch_size | activation | loss_tr | MAE_tr | loss_te | MAE_te | idx |
648-
|:-----------:|:------------:|:---------------:|:--------------------:|:--------------:|:----------:|:--------------:|:------------:|:------------:|:---------:|:--------:|:---------:|:--------:|:-----:|
649-
| False | sgd | 0.001 | | glorot_uniform | [8, 4] | 0.5 | 128 | tanh | 5.2905 | 1.58287 | 6.25027 | 1.73029 | 13396 |
650-
| False | sgd | 0.0001 | | glorot_uniform | [8] | 0 | 128 | selu | 5.2939 | 1.64328 | 7.14837 | 1.8074 | 8794 |
651-
| False | adam | 0.0001 | l2 | glorot_uniform | [8, 16, 8] | 0.5 | 128 | selu | 6.94665 | 1.71511 | 8.04218 | 1.85146 | 10254 |
652-
| True | sgd | 0.0001 | | uniform | [8, 4] | 0.5 | 32 | relu | 8.65953 | 2.05007 | 10.0391 | 2.14398 | 1355 |
653-
| True | rmsprop | 0.0001 | | he_uniform | [8, 16, 8] | 0.5 | 128 | tanh | 24.535 | 3.95683 | 26.6054 | 4.07911 | 13593 |
654-
655-
<br>
650+
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/ex_plots/04_tensorflow_results_table.png" data-zoomable width=800px style="padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px">
651+
<div class="caption">
652+
Figure 5: Results table for the best performing model architecture, showing both loss and MAE on training and validation sets. The consistent convergence suggests stable learning without overfitting.
653+
</div>
656654

657655
From this table, you could now perform a multitude of follow-up investigations. For example, take a look at the
658656
loss evolution during training:
@@ -670,7 +668,7 @@ plot_history(history_file=history_file, title="Training overview of best model")
670668

671669
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/ex_plots/04_tensorflow_architecture_comparison.png" data-zoomable width=800px style="padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px">
672670
<div class="caption">
673-
Figure 2: Training metrics for the best performing model architecture, showing both loss and MAE on training and validation sets. The consistent convergence suggests stable learning without overfitting.
671+
Figure 4: Training metrics for the best performing model architecture, showing both loss and MAE on training and validation sets. The consistent convergence suggests stable learning without overfitting.
674672
</div>
675673

676674
### Advanced Deep Learning Pitfalls
112 KB
Loading
81 KB
Loading

assets/scripts/04_tensorflow_advanced.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# Convert categorical data to numerical
3434
df = pd.get_dummies(df)
3535
print(f"Shape of dataset: {df.shape}")
36+
df.head()
3637

3738
# Split dataset into train and test set
3839
df_tr = df.sample(frac=0.8, random_state=0)

0 commit comments

Comments
 (0)