noshot 6.0.0__py3-none-any.whl → 8.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. noshot/data/ML TS XAI/ML/CNN(Image_for_Folders_5).ipynb +201 -0
  2. noshot/data/ML TS XAI/ML/CNN(Image_form_Folder_2).ipynb +201 -0
  3. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Balance Scale Dataset).ipynb +147 -0
  4. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Rice Dataset).ipynb +181 -0
  5. noshot/data/ML TS XAI/ML/ML 1/10. HMM Veterbi.ipynb +152 -0
  6. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Balance Scale Dataset).ipynb +117 -0
  7. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Iris Dataset).ipynb +156 -0
  8. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Sobar-72 Dataset).ipynb +215 -0
  9. noshot/data/ML TS XAI/ML/ML 1/3. LDA (Balance Scale Dataset).ipynb +78 -0
  10. noshot/data/ML TS XAI/ML/ML 1/3. LDA (NPHA Doctor Visits Dataset).ipynb +114 -0
  11. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Machine Dataset).ipynb +115 -0
  12. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Real Estate Dataset).ipynb +146 -0
  13. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Magic04 Dataset).ipynb +130 -0
  14. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Wine Dataset).ipynb +112 -0
  15. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +118 -0
  16. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Wine Dataset).ipynb +89 -0
  17. noshot/data/ML TS XAI/ML/ML 1/7. SVM (Rice Dataset).ipynb +120 -0
  18. noshot/data/ML TS XAI/ML/ML 1/8. FeedForward NN (Sobar72 Dataset).ipynb +262 -0
  19. noshot/data/ML TS XAI/ML/ML 1/9. CNN (Cifar10 Dataset).ipynb +156 -0
  20. noshot/data/ML TS XAI/ML/ML 2/1. PCA.ipynb +162 -0
  21. noshot/data/ML TS XAI/ML/ML 2/10. CNN.ipynb +100 -0
  22. noshot/data/ML TS XAI/ML/ML 2/11. HMM.ipynb +336 -0
  23. noshot/data/ML TS XAI/ML/ML 2/2. KNN.ipynb +149 -0
  24. noshot/data/ML TS XAI/ML/ML 2/3. LDA.ipynb +132 -0
  25. noshot/data/ML TS XAI/ML/ML 2/4. Linear Regression.ipynb +86 -0
  26. noshot/data/ML TS XAI/ML/ML 2/5. Logistic Regression.ipynb +115 -0
  27. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Titanic).ipynb +196 -0
  28. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Wine).ipynb +98 -0
  29. noshot/data/ML TS XAI/ML/ML 2/7. SVM Linear.ipynb +109 -0
  30. noshot/data/ML TS XAI/ML/ML 2/8. SVM Non-Linear.ipynb +195 -0
  31. noshot/data/ML TS XAI/ML/ML 2/9. FNN With Regularization.ipynb +189 -0
  32. noshot/data/ML TS XAI/ML/ML 2/9. FNN Without Regularization.ipynb +197 -0
  33. noshot/data/ML TS XAI/ML/ML 2/All in One Lab CIA 1 Q.ipynb +1087 -0
  34. noshot/data/ML TS XAI/ML/ML 3 (Latest)/1. PCA EDA.ipynb +274 -0
  35. noshot/data/ML TS XAI/ML/ML 3 (Latest)/10. CNN.ipynb +170 -0
  36. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 2.ipynb +1087 -0
  37. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 3.ipynb +178 -0
  38. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 4.ipynb +185 -0
  39. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM.ipynb +106 -0
  40. noshot/data/ML TS XAI/ML/ML 3 (Latest)/2. KNN.ipynb +177 -0
  41. noshot/data/ML TS XAI/ML/ML 3 (Latest)/3. LDA.ipynb +195 -0
  42. noshot/data/ML TS XAI/ML/ML 3 (Latest)/4. Linear Regression.ipynb +267 -0
  43. noshot/data/ML TS XAI/ML/ML 3 (Latest)/5. Logistic Regression.ipynb +104 -0
  44. noshot/data/ML TS XAI/ML/ML 3 (Latest)/6. Bayesian Classifier.ipynb +109 -0
  45. noshot/data/ML TS XAI/ML/ML 3 (Latest)/7. SVM.ipynb +220 -0
  46. noshot/data/ML TS XAI/ML/ML 3 (Latest)/8. MLP.ipynb +99 -0
  47. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge - Lasso.ipynb +211 -0
  48. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge Lasso 2.ipynb +99 -0
  49. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Image Load Example.ipynb +118 -0
  50. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Updated_Untitled.ipynb +603 -0
  51. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +691 -0
  52. {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/METADATA +1 -1
  53. noshot-8.0.0.dist-info/RECORD +60 -0
  54. {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/WHEEL +1 -1
  55. noshot/data/ML TS XAI/XAI/Q1.ipynb +0 -377
  56. noshot/data/ML TS XAI/XAI/Q2.ipynb +0 -362
  57. noshot/data/ML TS XAI/XAI/Q3.ipynb +0 -637
  58. noshot/data/ML TS XAI/XAI/Q4.ipynb +0 -206
  59. noshot/data/ML TS XAI/XAI/Q5.ipynb +0 -1018
  60. noshot-6.0.0.dist-info/RECORD +0 -14
  61. {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  62. {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,130 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "9be0f819-b381-4c85-ab7c-1535c061da6c",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import pandas as pd\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "import seaborn as sns\n",
13
+ "from sklearn.model_selection import train_test_split\n",
14
+ "from sklearn.linear_model import LogisticRegression\n",
15
+ "from sklearn.metrics import accuracy_score, classification_report, confusion_matrix, ConfusionMatrixDisplay, roc_curve, auc\n",
16
+ "from sklearn.preprocessing import MinMaxScaler"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": null,
22
+ "id": "a5c77375-2288-46a3-a1f8-6b0d47bfa320",
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "df = pd.read_csv('data/magic04.data', header=None)\n",
27
+ "df[10] = df[10].map({'g': 0, 'h': 1})\n",
28
+ "df.head()"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": null,
34
+ "id": "95a1be58-9838-4125-86c8-cb9f2d380dc3",
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "sns.pairplot(df[[0,1,2,10]], hue=10)"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "id": "09deb8ab-ac80-42de-b313-9dc92cbb1b28",
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "X = MinMaxScaler().fit_transform(df.drop(columns=[10]))\n",
49
+ "y = df[10]\n",
50
+ "\n",
51
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": null,
57
+ "id": "146b237b-1478-4780-b877-6fb903d94b31",
58
+ "metadata": {},
59
+ "outputs": [],
60
+ "source": [
61
+ "lr = LogisticRegression(max_iter=10000, random_state=0)\n",
62
+ "lr.fit(X_train, y_train)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "id": "a6757ba6-33bb-42d5-97c0-420e15f56b90",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "y_pred = lr.predict(X_test)\n",
73
+ "print(f\"Accuracy: {accuracy_score(y_test, y_pred)}\")\n",
74
+ "print(classification_report(y_test, y_pred))"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": null,
80
+ "id": "a9279e9f-f869-4f0d-ab36-107fff7d05be",
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": [
84
+ "cm = confusion_matrix(y_test, y_pred)\n",
85
+ "ConfusionMatrixDisplay(cm).plot()"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": null,
91
+ "id": "8a72838c-0530-4e67-a98c-0e29f72a504e",
92
+ "metadata": {},
93
+ "outputs": [],
94
+ "source": [
95
+ "y_pred_proba = lr.predict_proba(X_test)[:, 1]\n",
96
+ "fpr, tpr, _ = roc_curve(y_test, y_pred_proba)\n",
97
+ "roc_auc = auc(fpr, tpr)\n",
98
+ "\n",
99
+ "plt.plot(fpr, tpr, label=f'ROC curve (area = {roc_auc:.2f})')\n",
100
+ "plt.plot([0, 1], [0, 1], 'k--', label='No Skill')\n",
101
+ "plt.xlabel('False Positive Rate')\n",
102
+ "plt.ylabel('True Positive Rate')\n",
103
+ "plt.title('ROC Curve for Breast Cancer Classification')\n",
104
+ "plt.legend()\n",
105
+ "plt.show()"
106
+ ]
107
+ }
108
+ ],
109
+ "metadata": {
110
+ "kernelspec": {
111
+ "display_name": "Python 3 (ipykernel)",
112
+ "language": "python",
113
+ "name": "python3"
114
+ },
115
+ "language_info": {
116
+ "codemirror_mode": {
117
+ "name": "ipython",
118
+ "version": 3
119
+ },
120
+ "file_extension": ".py",
121
+ "mimetype": "text/x-python",
122
+ "name": "python",
123
+ "nbconvert_exporter": "python",
124
+ "pygments_lexer": "ipython3",
125
+ "version": "3.12.4"
126
+ }
127
+ },
128
+ "nbformat": 4,
129
+ "nbformat_minor": 5
130
+ }
@@ -0,0 +1,112 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "0fcc8bb7-4d22-4d3b-b58a-302bb24f8f2e",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import itertools\n",
11
+ "import numpy as np\n",
12
+ "import pandas as pd\n",
13
+ "import matplotlib.pyplot as plt\n",
14
+ "from sklearn import linear_model,datasets\n",
15
+ "from sklearn.model_selection import train_test_split\n",
16
+ "from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
17
+ "\n",
18
+ "import warnings\n",
19
+ "warnings.filterwarnings('ignore')"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": null,
25
+ "id": "d28e507b-fb15-4058-a161-656859a27c65",
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "wine = pd.read_csv('data/wine-dataset.csv')\n",
30
+ "print(\"Shape:\", wine.shape)\n",
31
+ "wine.head()"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": null,
37
+ "id": "c4e953da-6941-43f2-a9ce-aab907876d45",
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "source": [
41
+ "wine.columns"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": null,
47
+ "id": "9ee44a66-dc4a-4c79-9dab-eec60669dd8b",
48
+ "metadata": {},
49
+ "outputs": [],
50
+ "source": [
51
+ "X = wine.iloc[:, :13]\n",
52
+ "y = wine.iloc[:, 13]"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": null,
58
+ "id": "bd9d60dd-8272-46b4-8335-69d9751ed0c7",
59
+ "metadata": {},
60
+ "outputs": [],
61
+ "source": [
62
+ "X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.30, random_state=7)\n",
63
+ "\n",
64
+ "log_reg_model = linear_model.LogisticRegression()\n",
65
+ "log_reg_model.fit(X_train,y_train)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": null,
71
+ "id": "7c8fca42-c8d8-4334-9cc4-da4f5e1b0a1e",
72
+ "metadata": {},
73
+ "outputs": [],
74
+ "source": [
75
+ "log_reg_base_score = log_reg_model.score(X_test,y_test)\n",
76
+ "print(\"The score for the Logistic Regression Model is : \", log_reg_base_score)"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": null,
82
+ "id": "61bbb23e-cb29-41ae-9ea3-82e8d465c7f2",
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "cm = confusion_matrix(y_test, log_reg_model.predict(X_test))\n",
87
+ "ConfusionMatrixDisplay(cm).plot()"
88
+ ]
89
+ }
90
+ ],
91
+ "metadata": {
92
+ "kernelspec": {
93
+ "display_name": "Python 3 (ipykernel)",
94
+ "language": "python",
95
+ "name": "python3"
96
+ },
97
+ "language_info": {
98
+ "codemirror_mode": {
99
+ "name": "ipython",
100
+ "version": 3
101
+ },
102
+ "file_extension": ".py",
103
+ "mimetype": "text/x-python",
104
+ "name": "python",
105
+ "nbconvert_exporter": "python",
106
+ "pygments_lexer": "ipython3",
107
+ "version": "3.12.4"
108
+ }
109
+ },
110
+ "nbformat": 4,
111
+ "nbformat_minor": 5
112
+ }
@@ -0,0 +1,118 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "621687f2-cda2-449c-be36-91e2e0d4966d",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import pandas as pd\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "from sklearn.model_selection import train_test_split\n",
13
+ "from sklearn.naive_bayes import GaussianNB\n",
14
+ "from sklearn.metrics import accuracy_score, classification_report, confusion_matrix, ConfusionMatrixDisplay, roc_curve, auc\n",
15
+ "from sklearn.preprocessing import LabelEncoder"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": null,
21
+ "id": "e1793fec-c86e-4f2e-a9b7-dc1e68bffc1e",
22
+ "metadata": {},
23
+ "outputs": [],
24
+ "source": [
25
+ "df = pd.read_csv(\"data/agaricus-lepiota.data\", header=None)\n",
26
+ "df.head()"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": null,
32
+ "id": "d2944f82-5053-4703-abe8-c58b5147f4d9",
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "X = df.drop(columns=[0]).apply(LabelEncoder().fit_transform)\n",
37
+ "y = LabelEncoder().fit_transform(df[0])"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": null,
43
+ "id": "65d4d4b5-96a0-4a9d-8e95-635430642b49",
44
+ "metadata": {},
45
+ "outputs": [],
46
+ "source": [
47
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, stratify=y)\n",
48
+ "\n",
49
+ "nb = GaussianNB()\n",
50
+ "nb.fit(X_train, y_train)"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": null,
56
+ "id": "d453eb4a-81b5-4af1-a0af-9d644d4650ad",
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "y_pred = nb.predict(X_test)\n",
61
+ "print(f\"Accuracy: {accuracy_score(y_test, y_pred)}\")\n",
62
+ "print(classification_report(y_test, y_pred))"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "id": "b2c5580c-9f8a-48fb-b06a-af1087854391",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "ConfusionMatrixDisplay(confusion_matrix(y_test, y_pred)).plot()\n",
73
+ "plt.show()"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": null,
79
+ "id": "b64b2b36-199b-4292-b0f2-646e0136bd3f",
80
+ "metadata": {},
81
+ "outputs": [],
82
+ "source": [
83
+ "y_pred_proba = nb.predict_proba(X_test)[:, 1]\n",
84
+ "fpr, tpr, _ = roc_curve(y_test, y_pred_proba)\n",
85
+ "roc_auc = auc(fpr, tpr)\n",
86
+ "\n",
87
+ "plt.plot(fpr, tpr, label=f'ROC curve (area = {roc_auc:.2f})')\n",
88
+ "plt.plot([0, 1], [0, 1], 'k--', label='No Skill')\n",
89
+ "plt.xlabel('False Positive Rate')\n",
90
+ "plt.ylabel('True Positive Rate')\n",
91
+ "plt.title('ROC Curve for Agaricus-Lepiota Classification')\n",
92
+ "plt.legend()\n",
93
+ "plt.show()"
94
+ ]
95
+ }
96
+ ],
97
+ "metadata": {
98
+ "kernelspec": {
99
+ "display_name": "Python 3 (ipykernel)",
100
+ "language": "python",
101
+ "name": "python3"
102
+ },
103
+ "language_info": {
104
+ "codemirror_mode": {
105
+ "name": "ipython",
106
+ "version": 3
107
+ },
108
+ "file_extension": ".py",
109
+ "mimetype": "text/x-python",
110
+ "name": "python",
111
+ "nbconvert_exporter": "python",
112
+ "pygments_lexer": "ipython3",
113
+ "version": "3.12.4"
114
+ }
115
+ },
116
+ "nbformat": 4,
117
+ "nbformat_minor": 5
118
+ }
@@ -0,0 +1,89 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "939c616d-2779-4e21-adcf-1d070898d65b",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from sklearn import datasets\n",
11
+ "from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
12
+ "from sklearn.model_selection import train_test_split\n",
13
+ "from sklearn.naive_bayes import GaussianNB\n",
14
+ "import pandas as pd"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "id": "17720a0d-e788-4b1d-b2b2-a542f6b824a2",
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "wine = pd.read_csv('data/wine-dataset.csv')\n",
25
+ "print(wine.shape)"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": null,
31
+ "id": "a050923e-4382-4ff7-93bf-446b117c0ef5",
32
+ "metadata": {},
33
+ "outputs": [],
34
+ "source": [
35
+ "X = wine.iloc[:, :13]\n",
36
+ "X.head()"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "id": "9f1a4355-718e-40ed-b892-3e3d03c4ef3c",
43
+ "metadata": {},
44
+ "outputs": [],
45
+ "source": [
46
+ "y = wine.iloc[:, 13]\n",
47
+ "y"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": null,
53
+ "id": "dd3f31ef-c0d2-48dd-9fb7-338c10f9fbf9",
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 0)\n",
58
+ "\n",
59
+ "gnb = GaussianNB().fit(X_train, y_train)\n",
60
+ "gnb_predictions = gnb.predict(X_test)\n",
61
+ "accuracy = gnb.score(X_test, y_test)\n",
62
+ "accuracy\n",
63
+ "cm = confusion_matrix(y_test, gnb_predictions)\n",
64
+ "ConfusionMatrixDisplay(cm).plot()"
65
+ ]
66
+ }
67
+ ],
68
+ "metadata": {
69
+ "kernelspec": {
70
+ "display_name": "Python 3 (ipykernel)",
71
+ "language": "python",
72
+ "name": "python3"
73
+ },
74
+ "language_info": {
75
+ "codemirror_mode": {
76
+ "name": "ipython",
77
+ "version": 3
78
+ },
79
+ "file_extension": ".py",
80
+ "mimetype": "text/x-python",
81
+ "name": "python",
82
+ "nbconvert_exporter": "python",
83
+ "pygments_lexer": "ipython3",
84
+ "version": "3.12.4"
85
+ }
86
+ },
87
+ "nbformat": 4,
88
+ "nbformat_minor": 5
89
+ }
@@ -0,0 +1,120 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "4362a048-8226-4172-ad6b-97109238a33f",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import pandas as pd\n",
11
+ "import numpy as np\n",
12
+ "import seaborn as sns\n",
13
+ "import matplotlib.pyplot as plt\n",
14
+ "from sklearn.model_selection import train_test_split\n",
15
+ "from sklearn.metrics import accuracy_score, classification_report, confusion_matrix, ConfusionMatrixDisplay, roc_curve, auc\n",
16
+ "from sklearn.preprocessing import StandardScaler\n",
17
+ "from sklearn.decomposition import PCA\n",
18
+ "from sklearn.svm import SVC\n",
19
+ "from sklearn.pipeline import make_pipeline\n",
20
+ "from mlxtend.plotting import plot_decision_regions\n",
21
+ "from scipy.io import arff"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": null,
27
+ "id": "921ad1a4-cb33-4a06-862e-3c172da5ca3a",
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "data = arff.loadarff(\"data/rice.arff\")\n",
32
+ "df = pd.DataFrame(data[0])"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": null,
38
+ "id": "6c5497e5-76e2-461b-956a-e6fdb10707a9",
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "df['Class'] = df['Class'].map({b'Cammeo': 0, b'Osmancik': 1})\n",
43
+ "X = df.drop(columns=['Class'])\n",
44
+ "y = df['Class']\n",
45
+ "X = PCA(n_components=2).fit_transform(X)"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "id": "029f62b3-db5d-4284-b829-2708342ed440",
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
56
+ "\n",
57
+ "models = [\n",
58
+ " SVC(kernel='linear', C=1, degree=5, gamma=\"auto\", probability=True),\n",
59
+ " SVC(kernel='rbf', C=1, gamma='scale', probability=True),\n",
60
+ " SVC(kernel='poly', C=1, degree=5, gamma=\"auto\", probability=True)\n",
61
+ "]"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": null,
67
+ "id": "cad66559-bd1e-4dbb-b656-453aa8a4d0a0",
68
+ "metadata": {},
69
+ "outputs": [],
70
+ "source": [
71
+ "for model in models:\n",
72
+ " pipeline = make_pipeline(StandardScaler(), model)\n",
73
+ " pipeline.fit(X_train, y_train)\n",
74
+ " y_pred = pipeline.predict(X_test)\n",
75
+ " \n",
76
+ " print(f\"SVM ({model.kernel} kernel) Accuracy: {accuracy_score(y_test, y_pred):.2f}\")\n",
77
+ " print(classification_report(y_test, y_pred))\n",
78
+ " \n",
79
+ " plot_decision_regions(X=X_train, y=y_train.values, clf=pipeline, legend=2)\n",
80
+ " plt.title(f'SVM Decision Region Boundary ({model.kernel} kernel)')\n",
81
+ " plt.show()\n",
82
+ " \n",
83
+ " ConfusionMatrixDisplay(confusion_matrix(y_test, y_pred), display_labels=[0, 1]).plot(cmap='Blues')\n",
84
+ " plt.show()\n",
85
+ " \n",
86
+ " y_pred_proba = pipeline.predict_proba(X_test)[:, 1]\n",
87
+ " fpr, tpr, _ = roc_curve(y_test, y_pred_proba)\n",
88
+ " roc_auc = auc(fpr, tpr)\n",
89
+ " plt.plot(fpr, tpr, label=f'ROC curve (area = {roc_auc:.2f})')\n",
90
+ " plt.plot([0, 1], [0, 1], 'k--', label='No Skill')\n",
91
+ " plt.xlabel('False Positive Rate')\n",
92
+ " plt.ylabel('True Positive Rate')\n",
93
+ " plt.title('ROC Curve for Rice Classification')\n",
94
+ " plt.legend()\n",
95
+ " plt.show()"
96
+ ]
97
+ }
98
+ ],
99
+ "metadata": {
100
+ "kernelspec": {
101
+ "display_name": "Python 3 (ipykernel)",
102
+ "language": "python",
103
+ "name": "python3"
104
+ },
105
+ "language_info": {
106
+ "codemirror_mode": {
107
+ "name": "ipython",
108
+ "version": 3
109
+ },
110
+ "file_extension": ".py",
111
+ "mimetype": "text/x-python",
112
+ "name": "python",
113
+ "nbconvert_exporter": "python",
114
+ "pygments_lexer": "ipython3",
115
+ "version": "3.12.4"
116
+ }
117
+ },
118
+ "nbformat": 4,
119
+ "nbformat_minor": 5
120
+ }