noshot 4.0.0__py3-none-any.whl → 5.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.
- noshot/data/ML TS XAI/XAI/Q1.ipynb +535 -0
- noshot/data/ML TS XAI/XAI/Q2.ipynb +38129 -0
- noshot/data/ML TS XAI/XAI/Q3.ipynb +1340 -0
- noshot/data/ML TS XAI/XAI/Q4.ipynb +246 -0
- noshot/data/ML TS XAI/XAI/Q5.ipynb +2450 -0
- {noshot-4.0.0.dist-info → noshot-5.0.0.dist-info}/METADATA +1 -1
- noshot-5.0.0.dist-info/RECORD +14 -0
- noshot/data/ML TS XAI/ML/ML Lab CIA 2 (I Found Only This Check)/Copy_of_Pistachio_csv.ipynb +0 -269
- noshot/data/ML TS XAI/ML/ML Lab CIA 2 (I Found Only This Check)/weatherAUS.ipynb +0 -155
- noshot/data/ML TS XAI/ML/Main/1. EDA-PCA (Balance Scale Dataset).ipynb +0 -139
- noshot/data/ML TS XAI/ML/Main/1. EDA-PCA (Rice Dataset).ipynb +0 -181
- noshot/data/ML TS XAI/ML/Main/10. HMM Veterbi.ipynb +0 -228
- noshot/data/ML TS XAI/ML/Main/2. KNN (Balance Scale Dataset).ipynb +0 -117
- noshot/data/ML TS XAI/ML/Main/2. KNN (Iris Dataset).ipynb +0 -165
- noshot/data/ML TS XAI/ML/Main/2. KNN (Sobar-72 Dataset).ipynb +0 -251
- noshot/data/ML TS XAI/ML/Main/3. LDA (Balance Scale Dataset).ipynb +0 -78
- noshot/data/ML TS XAI/ML/Main/3. LDA (NPHA Doctor Visits Dataset).ipynb +0 -114
- noshot/data/ML TS XAI/ML/Main/4. Linear Regression (Machine Dataset).ipynb +0 -115
- noshot/data/ML TS XAI/ML/Main/4. Linear Regression (Real Estate Dataset).ipynb +0 -159
- noshot/data/ML TS XAI/ML/Main/5. Logistic Regression (Magic04 Dataset).ipynb +0 -200
- noshot/data/ML TS XAI/ML/Main/5. Logistic Regression (Wine Dataset).ipynb +0 -112
- noshot/data/ML TS XAI/ML/Main/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +0 -153
- noshot/data/ML TS XAI/ML/Main/6. Naive Bayes Classifier (Wine Dataset).ipynb +0 -89
- noshot/data/ML TS XAI/ML/Main/7. SVM (Rice Dataset).ipynb +0 -208
- noshot/data/ML TS XAI/ML/Main/8. FeedForward NN (Sobar72 Dataset).ipynb +0 -260
- noshot/data/ML TS XAI/ML/Main/9. CNN (Cifar10 Dataset).ipynb +0 -238
- noshot/data/ML TS XAI/ML/Main/data/agaricus-lepiota.data +0 -8124
- noshot/data/ML TS XAI/ML/Main/data/balance-scale.txt +0 -625
- noshot/data/ML TS XAI/ML/Main/data/doctor-visits.csv +0 -715
- noshot/data/ML TS XAI/ML/Main/data/iris.csv +0 -151
- noshot/data/ML TS XAI/ML/Main/data/machine-data.csv +0 -210
- noshot/data/ML TS XAI/ML/Main/data/magic04.data +0 -19020
- noshot/data/ML TS XAI/ML/Main/data/real-estate.xlsx +0 -0
- noshot/data/ML TS XAI/ML/Main/data/rice.arff +0 -3826
- noshot/data/ML TS XAI/ML/Main/data/sobar-72.csv +0 -73
- noshot/data/ML TS XAI/ML/Main/data/wine-dataset.csv +0 -179
- noshot/data/ML TS XAI/ML/Other Codes.ipynb +0 -158
- noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +0 -691
- noshot-4.0.0.dist-info/RECORD +0 -40
- {noshot-4.0.0.dist-info → noshot-5.0.0.dist-info}/WHEEL +0 -0
- {noshot-4.0.0.dist-info → noshot-5.0.0.dist-info}/licenses/LICENSE.txt +0 -0
- {noshot-4.0.0.dist-info → noshot-5.0.0.dist-info}/top_level.txt +0 -0
@@ -1,89 +0,0 @@
|
|
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
|
-
}
|
@@ -1,208 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"cells": [
|
3
|
-
{
|
4
|
-
"cell_type": "code",
|
5
|
-
"execution_count": null,
|
6
|
-
"id": "30043339",
|
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
|
-
"\n",
|
15
|
-
"from sklearn.model_selection import train_test_split\n",
|
16
|
-
"from sklearn.metrics import accuracy_score\n",
|
17
|
-
"from sklearn.preprocessing import MinMaxScaler\n",
|
18
|
-
"from sklearn.decomposition import PCA\n",
|
19
|
-
"from sklearn import svm\n",
|
20
|
-
"from sklearn.svm import SVC\n",
|
21
|
-
"from scipy.io import arff"
|
22
|
-
]
|
23
|
-
},
|
24
|
-
{
|
25
|
-
"cell_type": "code",
|
26
|
-
"execution_count": null,
|
27
|
-
"id": "74c26fca",
|
28
|
-
"metadata": {},
|
29
|
-
"outputs": [],
|
30
|
-
"source": [
|
31
|
-
"data = arff.loadarff(\"data/rice.arff\")\n",
|
32
|
-
"df = pd.DataFrame(data[0])\n",
|
33
|
-
"df.head()"
|
34
|
-
]
|
35
|
-
},
|
36
|
-
{
|
37
|
-
"cell_type": "code",
|
38
|
-
"execution_count": null,
|
39
|
-
"id": "51439c01",
|
40
|
-
"metadata": {},
|
41
|
-
"outputs": [],
|
42
|
-
"source": [
|
43
|
-
"df.info()"
|
44
|
-
]
|
45
|
-
},
|
46
|
-
{
|
47
|
-
"cell_type": "code",
|
48
|
-
"execution_count": null,
|
49
|
-
"id": "03e7a5d4",
|
50
|
-
"metadata": {},
|
51
|
-
"outputs": [],
|
52
|
-
"source": [
|
53
|
-
"df['Class'].unique()"
|
54
|
-
]
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"cell_type": "code",
|
58
|
-
"execution_count": null,
|
59
|
-
"id": "cf14dcf8",
|
60
|
-
"metadata": {},
|
61
|
-
"outputs": [],
|
62
|
-
"source": [
|
63
|
-
"df['Class'] = df['Class'].map({b'Cammeo':0, b'Osmancik':1})\n",
|
64
|
-
"df['Class'].unique()"
|
65
|
-
]
|
66
|
-
},
|
67
|
-
{
|
68
|
-
"cell_type": "code",
|
69
|
-
"execution_count": null,
|
70
|
-
"id": "dba18b10",
|
71
|
-
"metadata": {},
|
72
|
-
"outputs": [],
|
73
|
-
"source": [
|
74
|
-
"df.isnull().sum()"
|
75
|
-
]
|
76
|
-
},
|
77
|
-
{
|
78
|
-
"cell_type": "code",
|
79
|
-
"execution_count": null,
|
80
|
-
"id": "246346b1",
|
81
|
-
"metadata": {},
|
82
|
-
"outputs": [],
|
83
|
-
"source": [
|
84
|
-
"X = df.drop(columns=['Class'])\n",
|
85
|
-
"y = df['Class']"
|
86
|
-
]
|
87
|
-
},
|
88
|
-
{
|
89
|
-
"cell_type": "code",
|
90
|
-
"execution_count": null,
|
91
|
-
"id": "d182a204",
|
92
|
-
"metadata": {},
|
93
|
-
"outputs": [],
|
94
|
-
"source": [
|
95
|
-
"X = PCA(n_components=2).fit_transform(X)"
|
96
|
-
]
|
97
|
-
},
|
98
|
-
{
|
99
|
-
"cell_type": "code",
|
100
|
-
"execution_count": null,
|
101
|
-
"id": "f8e67728",
|
102
|
-
"metadata": {},
|
103
|
-
"outputs": [],
|
104
|
-
"source": [
|
105
|
-
"X.shape"
|
106
|
-
]
|
107
|
-
},
|
108
|
-
{
|
109
|
-
"cell_type": "code",
|
110
|
-
"execution_count": null,
|
111
|
-
"id": "99facee4",
|
112
|
-
"metadata": {},
|
113
|
-
"outputs": [],
|
114
|
-
"source": [
|
115
|
-
"plt.scatter(X[:,0], X[:,1], c=y, edgecolor=\"black\")\n",
|
116
|
-
"plt.show()"
|
117
|
-
]
|
118
|
-
},
|
119
|
-
{
|
120
|
-
"cell_type": "code",
|
121
|
-
"execution_count": null,
|
122
|
-
"id": "23da86fe-1c5d-4f57-ab29-a2bb6b060783",
|
123
|
-
"metadata": {},
|
124
|
-
"outputs": [],
|
125
|
-
"source": [
|
126
|
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"
|
127
|
-
]
|
128
|
-
},
|
129
|
-
{
|
130
|
-
"cell_type": "code",
|
131
|
-
"execution_count": null,
|
132
|
-
"id": "903cccff",
|
133
|
-
"metadata": {},
|
134
|
-
"outputs": [],
|
135
|
-
"source": [
|
136
|
-
"models=[\n",
|
137
|
-
" SVC(kernel='linear', C=1, degree=5, gamma=\"auto\", probability=True),\n",
|
138
|
-
" SVC(kernel='rbf', C=1, gamma='scale', probability=True),\n",
|
139
|
-
" SVC(kernel='poly', C=1, degree=5, gamma=\"auto\", probability=True)\n",
|
140
|
-
"]"
|
141
|
-
]
|
142
|
-
},
|
143
|
-
{
|
144
|
-
"cell_type": "code",
|
145
|
-
"execution_count": null,
|
146
|
-
"id": "ff7b81e7",
|
147
|
-
"metadata": {},
|
148
|
-
"outputs": [],
|
149
|
-
"source": [
|
150
|
-
"from sklearn.preprocessing import StandardScaler\n",
|
151
|
-
"from sklearn.pipeline import make_pipeline\n",
|
152
|
-
"from sklearn.metrics import classification_report,confusion_matrix,ConfusionMatrixDisplay\n",
|
153
|
-
"from sklearn.metrics import roc_curve, auc\n",
|
154
|
-
"from mlxtend.plotting import plot_decision_regions\n",
|
155
|
-
"\n",
|
156
|
-
"for model in models:\n",
|
157
|
-
" nonlinear_svm = make_pipeline(StandardScaler(), model)\n",
|
158
|
-
" nonlinear_svm.fit(X_train, y_train)\n",
|
159
|
-
" y_pred = nonlinear_svm.predict(X_test)\n",
|
160
|
-
" print(\"SVM Classification Report:\")\n",
|
161
|
-
" print(classification_report(y_test, y_pred))\n",
|
162
|
-
" print(f\"Accuracy: {accuracy_score(y_test, y_pred):.2f}\")\n",
|
163
|
-
" plot_decision_regions(X=X_train, \n",
|
164
|
-
" y=y_train.values,\n",
|
165
|
-
" clf=nonlinear_svm, \n",
|
166
|
-
" legend=2)\n",
|
167
|
-
"\n",
|
168
|
-
" plt.title('SVM Decision Region Boundary', size=16)\n",
|
169
|
-
" plt.show()\n",
|
170
|
-
" conf=confusion_matrix(y_test,y_pred)\n",
|
171
|
-
" ConfusionMatrixDisplay(conf,display_labels=[0,1]).plot(cmap='Blues')\n",
|
172
|
-
" plt.show()\n",
|
173
|
-
" y_pred_proba=nonlinear_svm.predict_proba(X_test)[:,1]\n",
|
174
|
-
" fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba) \n",
|
175
|
-
" roc_auc = auc(fpr, tpr)\n",
|
176
|
-
" \n",
|
177
|
-
" plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)\n",
|
178
|
-
" plt.plot([0, 1], [0, 1], 'k--', label='No Skill')\n",
|
179
|
-
" plt.xlabel('False Positive Rate')\n",
|
180
|
-
" plt.ylabel('True Positive Rate')\n",
|
181
|
-
" plt.title('ROC Curve for Rice Classification')\n",
|
182
|
-
" plt.legend()\n",
|
183
|
-
" plt.show()"
|
184
|
-
]
|
185
|
-
}
|
186
|
-
],
|
187
|
-
"metadata": {
|
188
|
-
"kernelspec": {
|
189
|
-
"display_name": "Python 3 (ipykernel)",
|
190
|
-
"language": "python",
|
191
|
-
"name": "python3"
|
192
|
-
},
|
193
|
-
"language_info": {
|
194
|
-
"codemirror_mode": {
|
195
|
-
"name": "ipython",
|
196
|
-
"version": 3
|
197
|
-
},
|
198
|
-
"file_extension": ".py",
|
199
|
-
"mimetype": "text/x-python",
|
200
|
-
"name": "python",
|
201
|
-
"nbconvert_exporter": "python",
|
202
|
-
"pygments_lexer": "ipython3",
|
203
|
-
"version": "3.12.4"
|
204
|
-
}
|
205
|
-
},
|
206
|
-
"nbformat": 4,
|
207
|
-
"nbformat_minor": 5
|
208
|
-
}
|
@@ -1,260 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"cells": [
|
3
|
-
{
|
4
|
-
"cell_type": "code",
|
5
|
-
"execution_count": null,
|
6
|
-
"metadata": {
|
7
|
-
"id": "aYlTWIqe5rL9"
|
8
|
-
},
|
9
|
-
"outputs": [],
|
10
|
-
"source": [
|
11
|
-
"import numpy as np\n",
|
12
|
-
"import pandas as pd\n",
|
13
|
-
"import seaborn as sns\n",
|
14
|
-
"import matplotlib.pyplot as plt\n",
|
15
|
-
"\n",
|
16
|
-
"import tensorflow as tf\n",
|
17
|
-
"from tensorflow.keras.models import Sequential\n",
|
18
|
-
"from tensorflow.keras.layers import Dense, Flatten\n",
|
19
|
-
"from tensorflow.keras.optimizers import Adam\n",
|
20
|
-
"from tensorflow.keras.losses import SparseCategoricalCrossentropy\n",
|
21
|
-
"from tensorflow.keras.metrics import SparseCategoricalAccuracy\n",
|
22
|
-
"\n",
|
23
|
-
"import warnings\n",
|
24
|
-
"warnings.filterwarnings('ignore')"
|
25
|
-
]
|
26
|
-
},
|
27
|
-
{
|
28
|
-
"cell_type": "code",
|
29
|
-
"execution_count": null,
|
30
|
-
"metadata": {
|
31
|
-
"colab": {
|
32
|
-
"base_uri": "https://localhost:8080/",
|
33
|
-
"height": 226
|
34
|
-
},
|
35
|
-
"id": "ejG3Obse5smj",
|
36
|
-
"outputId": "85d8cf13-eb83-49f6-e98f-0893fabb1cff"
|
37
|
-
},
|
38
|
-
"outputs": [],
|
39
|
-
"source": [
|
40
|
-
"df = pd.read_csv(\"data/sobar-72.csv\")\n",
|
41
|
-
"df.head()"
|
42
|
-
]
|
43
|
-
},
|
44
|
-
{
|
45
|
-
"cell_type": "code",
|
46
|
-
"execution_count": null,
|
47
|
-
"metadata": {
|
48
|
-
"id": "hLECDj5558Om"
|
49
|
-
},
|
50
|
-
"outputs": [],
|
51
|
-
"source": [
|
52
|
-
"X = df.drop(columns=['ca_cervix'])\n",
|
53
|
-
"y = df['ca_cervix']"
|
54
|
-
]
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"cell_type": "code",
|
58
|
-
"execution_count": null,
|
59
|
-
"metadata": {
|
60
|
-
"id": "MhA_LTNA5-49"
|
61
|
-
},
|
62
|
-
"outputs": [],
|
63
|
-
"source": [
|
64
|
-
"import matplotlib.pyplot as plt\n",
|
65
|
-
"from sklearn.model_selection import train_test_split\n",
|
66
|
-
"from tensorflow.keras import regularizers\n",
|
67
|
-
"from tensorflow.keras.layers import Dropout"
|
68
|
-
]
|
69
|
-
},
|
70
|
-
{
|
71
|
-
"cell_type": "code",
|
72
|
-
"execution_count": null,
|
73
|
-
"metadata": {
|
74
|
-
"id": "rjH4KJqq5_7-"
|
75
|
-
},
|
76
|
-
"outputs": [],
|
77
|
-
"source": [
|
78
|
-
"x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
|
79
|
-
"\n",
|
80
|
-
"y_train = tf.keras.utils.to_categorical(y_train, num_classes=2)\n",
|
81
|
-
"y_test = tf.keras.utils.to_categorical(y_test, num_classes=2)"
|
82
|
-
]
|
83
|
-
},
|
84
|
-
{
|
85
|
-
"cell_type": "code",
|
86
|
-
"execution_count": null,
|
87
|
-
"metadata": {
|
88
|
-
"id": "5lQVtYUC6A67"
|
89
|
-
},
|
90
|
-
"outputs": [],
|
91
|
-
"source": [
|
92
|
-
"model = tf.keras.models.Sequential([\n",
|
93
|
-
" tf.keras.layers.Dense(128, activation='relu', input_shape=(19,),\n",
|
94
|
-
" kernel_regularizer=regularizers.l2(0.001)),\n",
|
95
|
-
" Dropout(0.3),\n",
|
96
|
-
" tf.keras.layers.Dense(64, activation='relu',\n",
|
97
|
-
" kernel_regularizer=regularizers.l2(0.001)),\n",
|
98
|
-
" Dropout(0.3),\n",
|
99
|
-
" tf.keras.layers.Dense(units=2, activation='softmax')\n",
|
100
|
-
"])"
|
101
|
-
]
|
102
|
-
},
|
103
|
-
{
|
104
|
-
"cell_type": "code",
|
105
|
-
"execution_count": null,
|
106
|
-
"metadata": {
|
107
|
-
"id": "cgxMgB8q6Cjg"
|
108
|
-
},
|
109
|
-
"outputs": [],
|
110
|
-
"source": [
|
111
|
-
"model.compile(optimizer='adam',\n",
|
112
|
-
" loss='categorical_crossentropy',\n",
|
113
|
-
" metrics=['accuracy'])"
|
114
|
-
]
|
115
|
-
},
|
116
|
-
{
|
117
|
-
"cell_type": "code",
|
118
|
-
"execution_count": null,
|
119
|
-
"metadata": {
|
120
|
-
"id": "y71y0yDT6MnK"
|
121
|
-
},
|
122
|
-
"outputs": [],
|
123
|
-
"source": [
|
124
|
-
"early_stopping = tf.keras.callbacks.EarlyStopping(\n",
|
125
|
-
" monitor='val_loss',\n",
|
126
|
-
" patience=10,\n",
|
127
|
-
" restore_best_weights=True)"
|
128
|
-
]
|
129
|
-
},
|
130
|
-
{
|
131
|
-
"cell_type": "code",
|
132
|
-
"execution_count": null,
|
133
|
-
"metadata": {
|
134
|
-
"colab": {
|
135
|
-
"base_uri": "https://localhost:8080/"
|
136
|
-
},
|
137
|
-
"id": "1PZHOQQp6NpP",
|
138
|
-
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
139
|
-
},
|
140
|
-
"outputs": [],
|
141
|
-
"source": [
|
142
|
-
"history = model.fit(x_train, y_train,\n",
|
143
|
-
" epochs=50,\n",
|
144
|
-
" batch_size=32,\n",
|
145
|
-
" validation_split=0.2,\n",
|
146
|
-
" callbacks=[early_stopping],\n",
|
147
|
-
" verbose=1)"
|
148
|
-
]
|
149
|
-
},
|
150
|
-
{
|
151
|
-
"cell_type": "code",
|
152
|
-
"execution_count": null,
|
153
|
-
"metadata": {
|
154
|
-
"colab": {
|
155
|
-
"base_uri": "https://localhost:8080/",
|
156
|
-
"height": 362
|
157
|
-
},
|
158
|
-
"id": "qjhgjajp6O3J",
|
159
|
-
"outputId": "b04cb0d7-bc3f-4991-e5f8-c51698856ab7"
|
160
|
-
},
|
161
|
-
"outputs": [],
|
162
|
-
"source": [
|
163
|
-
"def plot_history(history):\n",
|
164
|
-
" plt.figure(figsize=(12, 5))\n",
|
165
|
-
"\n",
|
166
|
-
" # Plot loss\n",
|
167
|
-
" plt.subplot(1, 2, 1)\n",
|
168
|
-
" plt.plot(history.history['loss'], label='Training Loss')\n",
|
169
|
-
" plt.plot(history.history['val_loss'], label='Validation Loss')\n",
|
170
|
-
" plt.title('Training and Validation Loss')\n",
|
171
|
-
" plt.xlabel('Epoch')\n",
|
172
|
-
" plt.ylabel('Loss')\n",
|
173
|
-
" plt.legend()\n",
|
174
|
-
"\n",
|
175
|
-
" # Plot accuracy\n",
|
176
|
-
" plt.subplot(1, 2, 2)\n",
|
177
|
-
" plt.plot(history.history['accuracy'], label='Training Accuracy')\n",
|
178
|
-
" plt.plot(history.history['val_accuracy'], label='Validation Accuracy')\n",
|
179
|
-
" plt.title('Training and Validation Accuracy')\n",
|
180
|
-
" plt.xlabel('Epoch')\n",
|
181
|
-
" plt.ylabel('Accuracy')\n",
|
182
|
-
" plt.legend()\n",
|
183
|
-
"\n",
|
184
|
-
" plt.tight_layout()\n",
|
185
|
-
" plt.show()\n",
|
186
|
-
"\n",
|
187
|
-
"plot_history(history)\n",
|
188
|
-
"\n",
|
189
|
-
"loss, accuracy = model.evaluate(x_test, y_test)\n",
|
190
|
-
"print(f'Test accuracy: {accuracy:.4f}')\n",
|
191
|
-
"print(f'Test loss: {loss:.4f}')\n",
|
192
|
-
"\n",
|
193
|
-
"print(f\"Actual: {y_test[1]}, Predicted: {model.predict(x_test[:1])}\")"
|
194
|
-
]
|
195
|
-
},
|
196
|
-
{
|
197
|
-
"cell_type": "code",
|
198
|
-
"execution_count": null,
|
199
|
-
"metadata": {
|
200
|
-
"colab": {
|
201
|
-
"base_uri": "https://localhost:8080/",
|
202
|
-
"height": 1000
|
203
|
-
},
|
204
|
-
"id": "VaBGSYTs6Qeq",
|
205
|
-
"outputId": "39af0238-9045-412e-cd8b-258fdc133948"
|
206
|
-
},
|
207
|
-
"outputs": [],
|
208
|
-
"source": [
|
209
|
-
"from sklearn.metrics import classification_report,confusion_matrix,ConfusionMatrixDisplay,roc_curve, auc, accuracy_score\n",
|
210
|
-
"y_pred=model.predict(x_test)\n",
|
211
|
-
"y_test= [np.argmax(y, axis=None, out=None) for y in y_test]\n",
|
212
|
-
"y_pred= [np.argmax(y, axis=None, out=None) for y in y_pred]\n",
|
213
|
-
"print(\"Feed Forward Classification Report:\")\n",
|
214
|
-
"print(classification_report(y_test, y_pred))\n",
|
215
|
-
"print(f\"Accuracy: {accuracy_score(y_test, y_pred):.2f}\")\n",
|
216
|
-
"conf=confusion_matrix(y_test,y_pred)\n",
|
217
|
-
"ConfusionMatrixDisplay(conf,display_labels=[0,1]).plot(cmap='Blues')\n",
|
218
|
-
"plt.show()\n",
|
219
|
-
"y_pred_proba=model.predict(x_test)[:,1]\n",
|
220
|
-
"fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)\n",
|
221
|
-
"roc_auc = auc(fpr, tpr)\n",
|
222
|
-
"\n",
|
223
|
-
"plt.figure()\n",
|
224
|
-
"plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)\n",
|
225
|
-
"plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')\n",
|
226
|
-
"plt.xlim([0.0, 1.0])\n",
|
227
|
-
"plt.ylim([0.0, 1.05])\n",
|
228
|
-
"plt.xlabel('False Positive Rate')\n",
|
229
|
-
"plt.ylabel('True Positive Rate')\n",
|
230
|
-
"plt.title('Receiver Operating Characteristic')\n",
|
231
|
-
"plt.legend(loc=\"lower right\")\n",
|
232
|
-
"plt.show()"
|
233
|
-
]
|
234
|
-
}
|
235
|
-
],
|
236
|
-
"metadata": {
|
237
|
-
"colab": {
|
238
|
-
"provenance": []
|
239
|
-
},
|
240
|
-
"kernelspec": {
|
241
|
-
"display_name": "Python 3 (ipykernel)",
|
242
|
-
"language": "python",
|
243
|
-
"name": "python3"
|
244
|
-
},
|
245
|
-
"language_info": {
|
246
|
-
"codemirror_mode": {
|
247
|
-
"name": "ipython",
|
248
|
-
"version": 3
|
249
|
-
},
|
250
|
-
"file_extension": ".py",
|
251
|
-
"mimetype": "text/x-python",
|
252
|
-
"name": "python",
|
253
|
-
"nbconvert_exporter": "python",
|
254
|
-
"pygments_lexer": "ipython3",
|
255
|
-
"version": "3.12.4"
|
256
|
-
}
|
257
|
-
},
|
258
|
-
"nbformat": 4,
|
259
|
-
"nbformat_minor": 4
|
260
|
-
}
|