refactor(notebooks): remove redundant confusion matrix code for Sensor A and update reporting for Sensor B

This commit is contained in:
nuluh
2025-08-26 08:24:04 +07:00
parent f45614b6d9
commit 3ef656dd28

View File

@@ -862,17 +862,19 @@
"import matplotlib.pyplot as plt\n",
"from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
"\n",
"# Create a figure with subplots\n",
"fig, axes = plt.subplots(1, 2, figsize=(12, 5))\n",
"\n",
"cm = confusion_matrix(y, y_pred_svm_1) # -> ndarray\n",
"# Calculate confusion matrix\n",
"cm_A = confusion_matrix(y, y_pred_svm_1)\n",
"\n",
"# get the class labels\n",
"# Get class labels\n",
"labels = svm_model.classes_\n",
"\n",
"# Plot\n",
"disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=labels)\n",
"disp.plot(cmap=plt.cm.Blues) # You can change colormap\n",
"plt.title(\"Confusion Matrix of Sensor A Test on Dataset B\")\n",
"plt.show()"
"# Plot confusion matrix in first subplot\n",
"disp_A = ConfusionMatrixDisplay(confusion_matrix=cm_A, display_labels=labels)\n",
"disp_A.plot(ax=axes[0], cmap=plt.cm.Blues)\n",
"axes[0].set_title(\"Sensor A\")"
]
},
{
@@ -888,20 +890,26 @@
"metadata": {},
"outputs": [],
"source": [
"svm_model = load('D:/thesis/models/sensor2/SVM.joblib')\n",
"# svm_model = load('D:/thesis/models/sensor2/SVM with StandardScaler and PCA.joblib')\n",
"# svm_model = load('D:/thesis/models/sensor2/SVM.joblib')\n",
"svm_model = load('D:/thesis/models/sensor2/SVM with StandardScaler and PCA.joblib')\n",
"y_pred_svm_2 = svm_model.predict(X2b)\n",
"\n",
"# 5. Evaluate\n",
"print(\"Accuracy on Dataset B:\", accuracy_score(y, y_pred_svm_2))\n",
"print(classification_report(y, y_pred_svm_2))"
"\n",
"df = pd.DataFrame(classification_report(y, y_pred_svm_2, output_dict=True)).T\n",
"# Round numbers nicely and move 'accuracy' into a row that fits your desired layout\n",
"df_rounded = df.round(2)\n",
"\n",
"# Export to LaTeX\n",
"latex_table = df_rounded.to_latex(index=True, float_format=\"%.2f\", caption=\"Classification report on Dataset B\", label=\"tab:clf_report_auto\")\n",
"print(latex_table)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Confusion Matrix Sensor B"
"#### Confusion Matrix Sensor A and B"
]
},
{