Exp/74 exp cross dataset validation #107
@@ -862,17 +862,19 @@
|
|||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
|
"from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"# Create a figure with subplots\n",
|
||||||
|
"fig, axes = plt.subplots(1, 2, figsize=(12, 5))\n",
|
||||||
"\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",
|
"\n",
|
||||||
"# get the class labels\n",
|
"# Get class labels\n",
|
||||||
"labels = svm_model.classes_\n",
|
"labels = svm_model.classes_\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Plot\n",
|
"# Plot confusion matrix in first subplot\n",
|
||||||
"disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=labels)\n",
|
"disp_A = ConfusionMatrixDisplay(confusion_matrix=cm_A, display_labels=labels)\n",
|
||||||
"disp.plot(cmap=plt.cm.Blues) # You can change colormap\n",
|
"disp_A.plot(ax=axes[0], cmap=plt.cm.Blues)\n",
|
||||||
"plt.title(\"Confusion Matrix of Sensor A Test on Dataset B\")\n",
|
"axes[0].set_title(\"Sensor A\")"
|
||||||
"plt.show()"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -888,20 +890,26 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"svm_model = load('D:/thesis/models/sensor2/SVM.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",
|
"svm_model = load('D:/thesis/models/sensor2/SVM with StandardScaler and PCA.joblib')\n",
|
||||||
"y_pred_svm_2 = svm_model.predict(X2b)\n",
|
"y_pred_svm_2 = svm_model.predict(X2b)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# 5. Evaluate\n",
|
"# 5. Evaluate\n",
|
||||||
"print(\"Accuracy on Dataset B:\", accuracy_score(y, y_pred_svm_2))\n",
|
"\n",
|
||||||
"print(classification_report(y, y_pred_svm_2))"
|
"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",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"#### Confusion Matrix Sensor B"
|
"#### Confusion Matrix Sensor A and B"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user