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.
- noshot/data/ML TS XAI/ML/CNN(Image_for_Folders_5).ipynb +201 -0
- noshot/data/ML TS XAI/ML/CNN(Image_form_Folder_2).ipynb +201 -0
- noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Balance Scale Dataset).ipynb +147 -0
- noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Rice Dataset).ipynb +181 -0
- noshot/data/ML TS XAI/ML/ML 1/10. HMM Veterbi.ipynb +152 -0
- noshot/data/ML TS XAI/ML/ML 1/2. KNN (Balance Scale Dataset).ipynb +117 -0
- noshot/data/ML TS XAI/ML/ML 1/2. KNN (Iris Dataset).ipynb +156 -0
- noshot/data/ML TS XAI/ML/ML 1/2. KNN (Sobar-72 Dataset).ipynb +215 -0
- noshot/data/ML TS XAI/ML/ML 1/3. LDA (Balance Scale Dataset).ipynb +78 -0
- noshot/data/ML TS XAI/ML/ML 1/3. LDA (NPHA Doctor Visits Dataset).ipynb +114 -0
- noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Machine Dataset).ipynb +115 -0
- noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Real Estate Dataset).ipynb +146 -0
- noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Magic04 Dataset).ipynb +130 -0
- noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Wine Dataset).ipynb +112 -0
- noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +118 -0
- noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Wine Dataset).ipynb +89 -0
- noshot/data/ML TS XAI/ML/ML 1/7. SVM (Rice Dataset).ipynb +120 -0
- noshot/data/ML TS XAI/ML/ML 1/8. FeedForward NN (Sobar72 Dataset).ipynb +262 -0
- noshot/data/ML TS XAI/ML/ML 1/9. CNN (Cifar10 Dataset).ipynb +156 -0
- noshot/data/ML TS XAI/ML/ML 2/1. PCA.ipynb +162 -0
- noshot/data/ML TS XAI/ML/ML 2/10. CNN.ipynb +100 -0
- noshot/data/ML TS XAI/ML/ML 2/11. HMM.ipynb +336 -0
- noshot/data/ML TS XAI/ML/ML 2/2. KNN.ipynb +149 -0
- noshot/data/ML TS XAI/ML/ML 2/3. LDA.ipynb +132 -0
- noshot/data/ML TS XAI/ML/ML 2/4. Linear Regression.ipynb +86 -0
- noshot/data/ML TS XAI/ML/ML 2/5. Logistic Regression.ipynb +115 -0
- noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Titanic).ipynb +196 -0
- noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Wine).ipynb +98 -0
- noshot/data/ML TS XAI/ML/ML 2/7. SVM Linear.ipynb +109 -0
- noshot/data/ML TS XAI/ML/ML 2/8. SVM Non-Linear.ipynb +195 -0
- noshot/data/ML TS XAI/ML/ML 2/9. FNN With Regularization.ipynb +189 -0
- noshot/data/ML TS XAI/ML/ML 2/9. FNN Without Regularization.ipynb +197 -0
- noshot/data/ML TS XAI/ML/ML 2/All in One Lab CIA 1 Q.ipynb +1087 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/1. PCA EDA.ipynb +274 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/10. CNN.ipynb +170 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 2.ipynb +1087 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 3.ipynb +178 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 4.ipynb +185 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM.ipynb +106 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/2. KNN.ipynb +177 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/3. LDA.ipynb +195 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/4. Linear Regression.ipynb +267 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/5. Logistic Regression.ipynb +104 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/6. Bayesian Classifier.ipynb +109 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/7. SVM.ipynb +220 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/8. MLP.ipynb +99 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge - Lasso.ipynb +211 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge Lasso 2.ipynb +99 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/Image Load Example.ipynb +118 -0
- noshot/data/ML TS XAI/ML/ML 3 (Latest)/Updated_Untitled.ipynb +603 -0
- noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +691 -0
- {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/METADATA +1 -1
- noshot-8.0.0.dist-info/RECORD +60 -0
- {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/WHEEL +1 -1
- noshot/data/ML TS XAI/XAI/Q1.ipynb +0 -377
- noshot/data/ML TS XAI/XAI/Q2.ipynb +0 -362
- noshot/data/ML TS XAI/XAI/Q3.ipynb +0 -637
- noshot/data/ML TS XAI/XAI/Q4.ipynb +0 -206
- noshot/data/ML TS XAI/XAI/Q5.ipynb +0 -1018
- noshot-6.0.0.dist-info/RECORD +0 -14
- {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/licenses/LICENSE.txt +0 -0
- {noshot-6.0.0.dist-info → noshot-8.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,262 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"metadata": {
|
7
|
+
"colab": {
|
8
|
+
"base_uri": "https://localhost:8080/"
|
9
|
+
},
|
10
|
+
"id": "1PZHOQQp6NpP",
|
11
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
12
|
+
},
|
13
|
+
"outputs": [],
|
14
|
+
"source": [
|
15
|
+
"import numpy as np\n",
|
16
|
+
"import pandas as pd\n",
|
17
|
+
"import matplotlib.pyplot as plt\n",
|
18
|
+
"import tensorflow as tf\n",
|
19
|
+
"from tensorflow.keras.models import Sequential\n",
|
20
|
+
"from tensorflow.keras.layers import Dense, Dropout\n",
|
21
|
+
"from tensorflow.keras.optimizers import Adam\n",
|
22
|
+
"from tensorflow.keras import regularizers\n",
|
23
|
+
"from sklearn.model_selection import train_test_split\n",
|
24
|
+
"from sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay, accuracy_score, roc_curve, auc\n",
|
25
|
+
"\n",
|
26
|
+
"import warnings\n",
|
27
|
+
"warnings.filterwarnings('ignore')"
|
28
|
+
]
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"cell_type": "code",
|
32
|
+
"execution_count": null,
|
33
|
+
"metadata": {
|
34
|
+
"colab": {
|
35
|
+
"base_uri": "https://localhost:8080/"
|
36
|
+
},
|
37
|
+
"id": "1PZHOQQp6NpP",
|
38
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
39
|
+
},
|
40
|
+
"outputs": [],
|
41
|
+
"source": [
|
42
|
+
"df = pd.read_csv(\"data/sobar-72.csv\")\n",
|
43
|
+
"df.head()"
|
44
|
+
]
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"cell_type": "code",
|
48
|
+
"execution_count": null,
|
49
|
+
"metadata": {
|
50
|
+
"colab": {
|
51
|
+
"base_uri": "https://localhost:8080/"
|
52
|
+
},
|
53
|
+
"id": "1PZHOQQp6NpP",
|
54
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
55
|
+
},
|
56
|
+
"outputs": [],
|
57
|
+
"source": [
|
58
|
+
"X = df.drop(columns=['ca_cervix'])\n",
|
59
|
+
"y = tf.keras.utils.to_categorical(df['ca_cervix'], num_classes=2)"
|
60
|
+
]
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"cell_type": "code",
|
64
|
+
"execution_count": null,
|
65
|
+
"metadata": {
|
66
|
+
"colab": {
|
67
|
+
"base_uri": "https://localhost:8080/"
|
68
|
+
},
|
69
|
+
"id": "1PZHOQQp6NpP",
|
70
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
71
|
+
},
|
72
|
+
"outputs": [],
|
73
|
+
"source": [
|
74
|
+
"x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"
|
75
|
+
]
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"cell_type": "code",
|
79
|
+
"execution_count": null,
|
80
|
+
"metadata": {
|
81
|
+
"colab": {
|
82
|
+
"base_uri": "https://localhost:8080/"
|
83
|
+
},
|
84
|
+
"id": "1PZHOQQp6NpP",
|
85
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
86
|
+
},
|
87
|
+
"outputs": [],
|
88
|
+
"source": [
|
89
|
+
"model = Sequential([\n",
|
90
|
+
" Dense(128, activation='relu', input_shape=(19,), kernel_regularizer=regularizers.l2(0.001)),\n",
|
91
|
+
" Dropout(0.3),\n",
|
92
|
+
" Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)),\n",
|
93
|
+
" Dropout(0.3),\n",
|
94
|
+
" Dense(2, activation='softmax')\n",
|
95
|
+
"])\n",
|
96
|
+
"\n",
|
97
|
+
"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])"
|
98
|
+
]
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"cell_type": "code",
|
102
|
+
"execution_count": null,
|
103
|
+
"metadata": {
|
104
|
+
"colab": {
|
105
|
+
"base_uri": "https://localhost:8080/"
|
106
|
+
},
|
107
|
+
"id": "1PZHOQQp6NpP",
|
108
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
109
|
+
},
|
110
|
+
"outputs": [],
|
111
|
+
"source": [
|
112
|
+
"early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss', \n",
|
113
|
+
" patience=10, \n",
|
114
|
+
" restore_best_weights=True)\n",
|
115
|
+
"history = model.fit(x_train, y_train, epochs=50, \n",
|
116
|
+
" batch_size=32, validation_split=0.2,\n",
|
117
|
+
" callbacks=[early_stopping], verbose=1)"
|
118
|
+
]
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"cell_type": "code",
|
122
|
+
"execution_count": null,
|
123
|
+
"metadata": {
|
124
|
+
"colab": {
|
125
|
+
"base_uri": "https://localhost:8080/"
|
126
|
+
},
|
127
|
+
"id": "1PZHOQQp6NpP",
|
128
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
129
|
+
},
|
130
|
+
"outputs": [],
|
131
|
+
"source": [
|
132
|
+
"def plot_history(history):\n",
|
133
|
+
" plt.figure(figsize=(12, 5))\n",
|
134
|
+
"\n",
|
135
|
+
" plt.subplot(1, 2, 1)\n",
|
136
|
+
" plt.plot(history.history['loss'], label='Training Loss')\n",
|
137
|
+
" plt.plot(history.history['val_loss'], label='Validation Loss')\n",
|
138
|
+
" plt.title('Loss')\n",
|
139
|
+
" plt.xlabel('Epoch')\n",
|
140
|
+
" plt.ylabel('Loss')\n",
|
141
|
+
" plt.legend()\n",
|
142
|
+
"\n",
|
143
|
+
" plt.subplot(1, 2, 2)\n",
|
144
|
+
" plt.plot(history.history['accuracy'], label='Training Accuracy')\n",
|
145
|
+
" plt.plot(history.history['val_accuracy'], label='Validation Accuracy')\n",
|
146
|
+
" plt.title('Accuracy')\n",
|
147
|
+
" plt.xlabel('Epoch')\n",
|
148
|
+
" plt.ylabel('Accuracy')\n",
|
149
|
+
" plt.legend()\n",
|
150
|
+
"\n",
|
151
|
+
" plt.tight_layout()\n",
|
152
|
+
" plt.show()\n",
|
153
|
+
"\n",
|
154
|
+
"plot_history(history)"
|
155
|
+
]
|
156
|
+
},
|
157
|
+
{
|
158
|
+
"cell_type": "code",
|
159
|
+
"execution_count": null,
|
160
|
+
"metadata": {
|
161
|
+
"colab": {
|
162
|
+
"base_uri": "https://localhost:8080/"
|
163
|
+
},
|
164
|
+
"id": "1PZHOQQp6NpP",
|
165
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
166
|
+
},
|
167
|
+
"outputs": [],
|
168
|
+
"source": [
|
169
|
+
"loss, accuracy = model.evaluate(x_test, y_test)\n",
|
170
|
+
"print(f'Test accuracy: {accuracy:.4f}')\n",
|
171
|
+
"print(f'Test loss: {loss:.4f}')"
|
172
|
+
]
|
173
|
+
},
|
174
|
+
{
|
175
|
+
"cell_type": "code",
|
176
|
+
"execution_count": null,
|
177
|
+
"metadata": {
|
178
|
+
"colab": {
|
179
|
+
"base_uri": "https://localhost:8080/"
|
180
|
+
},
|
181
|
+
"id": "1PZHOQQp6NpP",
|
182
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
183
|
+
},
|
184
|
+
"outputs": [],
|
185
|
+
"source": [
|
186
|
+
"y_pred = np.argmax(model.predict(x_test), axis=1)\n",
|
187
|
+
"y_test = np.argmax(y_test, axis=1)\n",
|
188
|
+
"print(\"Classification Report:\")\n",
|
189
|
+
"print(classification_report(y_test, y_pred))\n",
|
190
|
+
"print(f\"Accuracy: {accuracy_score(y_test, y_pred):.2f}\")"
|
191
|
+
]
|
192
|
+
},
|
193
|
+
{
|
194
|
+
"cell_type": "code",
|
195
|
+
"execution_count": null,
|
196
|
+
"metadata": {
|
197
|
+
"colab": {
|
198
|
+
"base_uri": "https://localhost:8080/"
|
199
|
+
},
|
200
|
+
"id": "1PZHOQQp6NpP",
|
201
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
202
|
+
},
|
203
|
+
"outputs": [],
|
204
|
+
"source": [
|
205
|
+
"conf = confusion_matrix(y_test, y_pred)\n",
|
206
|
+
"ConfusionMatrixDisplay(conf).plot(cmap='Blues')\n",
|
207
|
+
"plt.show()"
|
208
|
+
]
|
209
|
+
},
|
210
|
+
{
|
211
|
+
"cell_type": "code",
|
212
|
+
"execution_count": null,
|
213
|
+
"metadata": {
|
214
|
+
"colab": {
|
215
|
+
"base_uri": "https://localhost:8080/"
|
216
|
+
},
|
217
|
+
"id": "1PZHOQQp6NpP",
|
218
|
+
"outputId": "c1d34cfd-5b74-4f42-aef1-74bbfc6aec95"
|
219
|
+
},
|
220
|
+
"outputs": [],
|
221
|
+
"source": [
|
222
|
+
"y_pred_proba = model.predict(x_test)[:, 1]\n",
|
223
|
+
"fpr, tpr, _ = roc_curve(y_test, y_pred_proba)\n",
|
224
|
+
"roc_auc = auc(fpr, tpr)\n",
|
225
|
+
"\n",
|
226
|
+
"plt.plot(fpr, tpr, label=f'ROC curve (area = {roc_auc:.2f})', color='darkorange')\n",
|
227
|
+
"plt.plot([0, 1], [0, 1], color='navy', linestyle='--')\n",
|
228
|
+
"plt.xlim([0.0, 1.0])\n",
|
229
|
+
"plt.ylim([0.0, 1.05])\n",
|
230
|
+
"plt.xlabel('False Positive Rate')\n",
|
231
|
+
"plt.ylabel('True Positive Rate')\n",
|
232
|
+
"plt.title('Receiver Operating Characteristic')\n",
|
233
|
+
"plt.legend(loc=\"lower right\")\n",
|
234
|
+
"plt.show()"
|
235
|
+
]
|
236
|
+
}
|
237
|
+
],
|
238
|
+
"metadata": {
|
239
|
+
"colab": {
|
240
|
+
"provenance": []
|
241
|
+
},
|
242
|
+
"kernelspec": {
|
243
|
+
"display_name": "NEW-VENV-1",
|
244
|
+
"language": "python",
|
245
|
+
"name": "new-venv-1"
|
246
|
+
},
|
247
|
+
"language_info": {
|
248
|
+
"codemirror_mode": {
|
249
|
+
"name": "ipython",
|
250
|
+
"version": 3
|
251
|
+
},
|
252
|
+
"file_extension": ".py",
|
253
|
+
"mimetype": "text/x-python",
|
254
|
+
"name": "python",
|
255
|
+
"nbconvert_exporter": "python",
|
256
|
+
"pygments_lexer": "ipython3",
|
257
|
+
"version": "3.11.5"
|
258
|
+
}
|
259
|
+
},
|
260
|
+
"nbformat": 4,
|
261
|
+
"nbformat_minor": 4
|
262
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"metadata": {
|
7
|
+
"id": "wHmdCsrz61l7"
|
8
|
+
},
|
9
|
+
"outputs": [],
|
10
|
+
"source": [
|
11
|
+
"import tensorflow as tf\n",
|
12
|
+
"from tensorflow import keras\n",
|
13
|
+
"from tensorflow.keras import layers\n",
|
14
|
+
"from keras.datasets import cifar10\n",
|
15
|
+
"from keras.utils import to_categorical\n",
|
16
|
+
"import matplotlib.pyplot as plt\n",
|
17
|
+
"from sklearn.metrics import roc_curve, auc\n",
|
18
|
+
"from sklearn.preprocessing import label_binarize\n",
|
19
|
+
"\n",
|
20
|
+
"import warnings\n",
|
21
|
+
"warnings.filterwarnings('ignore')"
|
22
|
+
]
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"cell_type": "code",
|
26
|
+
"execution_count": null,
|
27
|
+
"metadata": {
|
28
|
+
"id": "wHmdCsrz61l7"
|
29
|
+
},
|
30
|
+
"outputs": [],
|
31
|
+
"source": [
|
32
|
+
"(X_train, y_train), (X_test, y_test) = cifar10.load_data()"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"cell_type": "code",
|
37
|
+
"execution_count": null,
|
38
|
+
"metadata": {
|
39
|
+
"id": "wHmdCsrz61l7"
|
40
|
+
},
|
41
|
+
"outputs": [],
|
42
|
+
"source": [
|
43
|
+
"def preprocess_data(X, y):\n",
|
44
|
+
" X = X.astype('float32') / 255.0\n",
|
45
|
+
" y = to_categorical(y, num_classes=10)\n",
|
46
|
+
" return X, y"
|
47
|
+
]
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"cell_type": "code",
|
51
|
+
"execution_count": null,
|
52
|
+
"metadata": {
|
53
|
+
"id": "wHmdCsrz61l7"
|
54
|
+
},
|
55
|
+
"outputs": [],
|
56
|
+
"source": [
|
57
|
+
"x_train, y_train = preprocess_data(X_train, y_train)\n",
|
58
|
+
"x_test, y_test = preprocess_data(X_test, y_test)"
|
59
|
+
]
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"cell_type": "code",
|
63
|
+
"execution_count": null,
|
64
|
+
"metadata": {
|
65
|
+
"id": "wHmdCsrz61l7"
|
66
|
+
},
|
67
|
+
"outputs": [],
|
68
|
+
"source": [
|
69
|
+
"model = keras.Sequential([\n",
|
70
|
+
" layers.Conv2D(32, kernel_size=(3, 3), activation=\"relu\", input_shape=(32, 32, 3)),\n",
|
71
|
+
" layers.MaxPooling2D(pool_size=(2, 2)),\n",
|
72
|
+
" layers.Conv2D(64, kernel_size=(3, 3), activation=\"relu\"),\n",
|
73
|
+
" layers.MaxPooling2D(pool_size=(2, 2)),\n",
|
74
|
+
" layers.Flatten(),\n",
|
75
|
+
" layers.Dense(10, activation=\"softmax\")\n",
|
76
|
+
"])\n",
|
77
|
+
"\n",
|
78
|
+
"model.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\", metrics=[\"accuracy\"])"
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"cell_type": "code",
|
83
|
+
"execution_count": null,
|
84
|
+
"metadata": {
|
85
|
+
"id": "wHmdCsrz61l7"
|
86
|
+
},
|
87
|
+
"outputs": [],
|
88
|
+
"source": [
|
89
|
+
"early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss', \n",
|
90
|
+
" patience=10, \n",
|
91
|
+
" restore_best_weights=True)\n",
|
92
|
+
"\n",
|
93
|
+
"history = model.fit(x_train, y_train, epochs=5, \n",
|
94
|
+
" batch_size=32, validation_split=0.2, callbacks=[early_stopping])"
|
95
|
+
]
|
96
|
+
},
|
97
|
+
{
|
98
|
+
"cell_type": "code",
|
99
|
+
"execution_count": null,
|
100
|
+
"metadata": {
|
101
|
+
"id": "wHmdCsrz61l7"
|
102
|
+
},
|
103
|
+
"outputs": [],
|
104
|
+
"source": [
|
105
|
+
"y_test_bin = label_binarize(y_test, classes=list(range(10)))\n",
|
106
|
+
"y_pred_proba = model.predict(x_test)"
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"cell_type": "code",
|
111
|
+
"execution_count": null,
|
112
|
+
"metadata": {
|
113
|
+
"id": "wHmdCsrz61l7"
|
114
|
+
},
|
115
|
+
"outputs": [],
|
116
|
+
"source": [
|
117
|
+
"fpr, tpr, _ = roc_curve(y_test_bin[:, 0], y_pred_proba[:, 0])\n",
|
118
|
+
"roc_auc = auc(fpr, tpr)\n",
|
119
|
+
"\n",
|
120
|
+
"plt.plot(fpr, tpr, color='darkorange', lw=2, label=f'Class 0 ROC curve (area = {roc_auc:.2f})')\n",
|
121
|
+
"plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')\n",
|
122
|
+
"plt.xlim([0.0, 1.0])\n",
|
123
|
+
"plt.ylim([0.0, 1.05])\n",
|
124
|
+
"plt.xlabel('False Positive Rate')\n",
|
125
|
+
"plt.ylabel('True Positive Rate')\n",
|
126
|
+
"plt.title('ROC Curve for Class 0')\n",
|
127
|
+
"plt.legend(loc=\"lower right\")\n",
|
128
|
+
"plt.show()"
|
129
|
+
]
|
130
|
+
}
|
131
|
+
],
|
132
|
+
"metadata": {
|
133
|
+
"colab": {
|
134
|
+
"provenance": []
|
135
|
+
},
|
136
|
+
"kernelspec": {
|
137
|
+
"display_name": "NEW-VENV-1",
|
138
|
+
"language": "python",
|
139
|
+
"name": "new-venv-1"
|
140
|
+
},
|
141
|
+
"language_info": {
|
142
|
+
"codemirror_mode": {
|
143
|
+
"name": "ipython",
|
144
|
+
"version": 3
|
145
|
+
},
|
146
|
+
"file_extension": ".py",
|
147
|
+
"mimetype": "text/x-python",
|
148
|
+
"name": "python",
|
149
|
+
"nbconvert_exporter": "python",
|
150
|
+
"pygments_lexer": "ipython3",
|
151
|
+
"version": "3.11.5"
|
152
|
+
}
|
153
|
+
},
|
154
|
+
"nbformat": 4,
|
155
|
+
"nbformat_minor": 4
|
156
|
+
}
|
@@ -0,0 +1,162 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"id": "cfbb1d58-7c8f-4a0c-b6e2-914469a7e49d",
|
6
|
+
"metadata": {},
|
7
|
+
"source": [
|
8
|
+
"Principal Component Analysis & Exploratory Data Analysis"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"cell_type": "code",
|
13
|
+
"execution_count": null,
|
14
|
+
"id": "d3b0a49d-a326-4bb3-b868-cfeaaaa50d3e",
|
15
|
+
"metadata": {},
|
16
|
+
"outputs": [],
|
17
|
+
"source": [
|
18
|
+
"#required packages.\n",
|
19
|
+
"\n",
|
20
|
+
"import pandas as pd\n",
|
21
|
+
"import matplotlib.pyplot as plt\n",
|
22
|
+
"import numpy as np\n",
|
23
|
+
"from sklearn.preprocessing import StandardScaler\n",
|
24
|
+
"from sklearn.decomposition import PCA"
|
25
|
+
]
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"cell_type": "code",
|
29
|
+
"execution_count": null,
|
30
|
+
"id": "e1c8f709-35bc-4eec-987e-cd1e6780d877",
|
31
|
+
"metadata": {},
|
32
|
+
"outputs": [],
|
33
|
+
"source": [
|
34
|
+
"#Load dataset, print few rows, get info, describe dataset.\n",
|
35
|
+
"\n",
|
36
|
+
"df=pd.read_csv(\"E:/126156055/dataset_ex_1.csv\",names=[\"class name\",'left-weight','left-distance','right-weight','right-distance'])\n",
|
37
|
+
"print(\"First Five rows : \\n\",df.head())\n",
|
38
|
+
"print(\"\\nInfo : \\n\",df.info)\n",
|
39
|
+
"print(\"\\nDescribe : \\n\",df.describe())"
|
40
|
+
]
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"cell_type": "markdown",
|
44
|
+
"id": "ee7c0104-4a32-4c28-b3fc-080c77461100",
|
45
|
+
"metadata": {},
|
46
|
+
"source": [
|
47
|
+
"PCA"
|
48
|
+
]
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"cell_type": "code",
|
52
|
+
"execution_count": null,
|
53
|
+
"id": "6af99020-e017-478a-9e18-ed098f4167ed",
|
54
|
+
"metadata": {},
|
55
|
+
"outputs": [],
|
56
|
+
"source": [
|
57
|
+
"features=['left-weight','left-distance','right-weight','right-distance']\n",
|
58
|
+
"x=df.loc[:,features]\n",
|
59
|
+
"y=df.loc[:,'class name']\n",
|
60
|
+
"x=StandardScaler().fit_transform(x)\n",
|
61
|
+
"x"
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"cell_type": "code",
|
66
|
+
"execution_count": null,
|
67
|
+
"id": "ff575de1-483a-48c2-be39-2cf91b082aff",
|
68
|
+
"metadata": {},
|
69
|
+
"outputs": [],
|
70
|
+
"source": [
|
71
|
+
"pca=PCA(n_components=2)\n",
|
72
|
+
"pca_x=pca.fit_transform(x)\n",
|
73
|
+
"pca_x"
|
74
|
+
]
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"cell_type": "code",
|
78
|
+
"execution_count": null,
|
79
|
+
"id": "9f7d8296-1c1e-47ed-a2c5-cf499423dbfa",
|
80
|
+
"metadata": {},
|
81
|
+
"outputs": [],
|
82
|
+
"source": [
|
83
|
+
"principal_df=pd.DataFrame(pca_x,columns=['pc1','pc2'])\n",
|
84
|
+
"principal_df"
|
85
|
+
]
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"cell_type": "code",
|
89
|
+
"execution_count": null,
|
90
|
+
"id": "f1481c63-6fbf-4028-a88f-3ef492e44119",
|
91
|
+
"metadata": {},
|
92
|
+
"outputs": [],
|
93
|
+
"source": [
|
94
|
+
"final_df=pd.concat([principal_df,df['class name']],axis=1)\n",
|
95
|
+
"final_df"
|
96
|
+
]
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"cell_type": "code",
|
100
|
+
"execution_count": null,
|
101
|
+
"id": "72d8f4bc-0db2-4a1a-bac2-403455b6b3a3",
|
102
|
+
"metadata": {},
|
103
|
+
"outputs": [],
|
104
|
+
"source": [
|
105
|
+
"plt.xlabel(\"Component 1\")\n",
|
106
|
+
"plt.ylabel(\"Component 2\")\n",
|
107
|
+
"plt.title(\"2 Component PCA\")\n",
|
108
|
+
"targets=['L','B','R']\n",
|
109
|
+
"colors=['r','g','b']\n",
|
110
|
+
"for target,color in zip(targets,colors):\n",
|
111
|
+
" indicesToKeep=final_df['class name']==target\n",
|
112
|
+
" plt.scatter(final_df.loc[indicesToKeep,'pc1'],final_df.loc[indicesToKeep,\"pc2\"],c=color,s=20)\n",
|
113
|
+
"\n",
|
114
|
+
"plt.legend(targets)\n",
|
115
|
+
"plt.grid()\n",
|
116
|
+
" "
|
117
|
+
]
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"cell_type": "markdown",
|
121
|
+
"id": "58a3f3db-1a05-4dd7-b428-b28ef3061b3b",
|
122
|
+
"metadata": {},
|
123
|
+
"source": [
|
124
|
+
"EDA"
|
125
|
+
]
|
126
|
+
},
|
127
|
+
{
|
128
|
+
"cell_type": "code",
|
129
|
+
"execution_count": null,
|
130
|
+
"id": "9ad2b51e-4a22-4285-959e-38d3c7ec55a0",
|
131
|
+
"metadata": {},
|
132
|
+
"outputs": [],
|
133
|
+
"source": [
|
134
|
+
"df2=df.copy()\n",
|
135
|
+
"print(\"\\nShape : \",df2.shape)\n",
|
136
|
+
"print('\\nColumns : ',df2.columns)\n",
|
137
|
+
"print('\\nDtype : ',df2.dtypes)"
|
138
|
+
]
|
139
|
+
}
|
140
|
+
],
|
141
|
+
"metadata": {
|
142
|
+
"kernelspec": {
|
143
|
+
"display_name": "Python 3 (ipykernel)",
|
144
|
+
"language": "python",
|
145
|
+
"name": "python3"
|
146
|
+
},
|
147
|
+
"language_info": {
|
148
|
+
"codemirror_mode": {
|
149
|
+
"name": "ipython",
|
150
|
+
"version": 3
|
151
|
+
},
|
152
|
+
"file_extension": ".py",
|
153
|
+
"mimetype": "text/x-python",
|
154
|
+
"name": "python",
|
155
|
+
"nbconvert_exporter": "python",
|
156
|
+
"pygments_lexer": "ipython3",
|
157
|
+
"version": "3.12.4"
|
158
|
+
}
|
159
|
+
},
|
160
|
+
"nbformat": 4,
|
161
|
+
"nbformat_minor": 5
|
162
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"metadata": {
|
7
|
+
"colab": {
|
8
|
+
"base_uri": "https://localhost:8080/",
|
9
|
+
"height": 1000
|
10
|
+
},
|
11
|
+
"executionInfo": {
|
12
|
+
"elapsed": 823916,
|
13
|
+
"status": "ok",
|
14
|
+
"timestamp": 1744091957068,
|
15
|
+
"user": {
|
16
|
+
"displayName": "Jaison A",
|
17
|
+
"userId": "07006398627763032071"
|
18
|
+
},
|
19
|
+
"user_tz": -330
|
20
|
+
},
|
21
|
+
"id": "k8tJEU5Y7IP8",
|
22
|
+
"outputId": "5121ca10-6db7-4c99-d4e7-d6cf30e3f5ae"
|
23
|
+
},
|
24
|
+
"outputs": [],
|
25
|
+
"source": [
|
26
|
+
"from keras.datasets import mnist\n",
|
27
|
+
"from keras.models import Sequential\n",
|
28
|
+
"from keras.layers import Dense, Dropout, Conv2D, MaxPool2D, Flatten\n",
|
29
|
+
"# Instead of 'from keras.utils import np_utils', use the following line:\n",
|
30
|
+
"from tensorflow.keras.utils import to_categorical # import to_categorical directly\n",
|
31
|
+
"from sklearn.metrics import accuracy_score\n",
|
32
|
+
"import matplotlib.pyplot as plt\n",
|
33
|
+
"import numpy as np\n",
|
34
|
+
"\n",
|
35
|
+
"\n",
|
36
|
+
"(X_train, y_train), (X_test, y_test) = mnist.load_data()\n",
|
37
|
+
"X_train = X_train.reshape(X_train.shape[0], 28, 28, 1)\n",
|
38
|
+
"X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)\n",
|
39
|
+
"X_train = X_train.astype('float32')\n",
|
40
|
+
"X_test = X_test.astype('float32')\n",
|
41
|
+
"X_train /= 255\n",
|
42
|
+
"X_test /= 255\n",
|
43
|
+
"n_classes = 10\n",
|
44
|
+
"print(\"Shape before one-hot encoding: \", y_train.shape)\n",
|
45
|
+
"# Use to_categorical directly:\n",
|
46
|
+
"Y_train = to_categorical(y_train, n_classes) # Use to_categorical directly\n",
|
47
|
+
"Y_test = to_categorical(y_test, n_classes) # Use to_categorical directly\n",
|
48
|
+
"print(\"Shape after one-hot encoding: \", Y_train.shape)\n",
|
49
|
+
"model = Sequential()\n",
|
50
|
+
"model.add(Conv2D(25, kernel_size=(3,3), strides=(1,1), padding='valid', activation='relu', input_shape=(28,28,1)))\n",
|
51
|
+
"model.add(MaxPool2D(pool_size=(1,1)))\n",
|
52
|
+
"model.add(Flatten())\n",
|
53
|
+
"model.add(Dense(100, activation='relu'))\n",
|
54
|
+
"model.add(Dense(10, activation='softmax'))\n",
|
55
|
+
"model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')\n",
|
56
|
+
"history = model.fit(X_train, Y_train, batch_size=128, epochs=10, validation_data=(X_test, Y_test))\n",
|
57
|
+
"print(history.history.keys())\n",
|
58
|
+
"plt.plot(history.history['accuracy'])\n",
|
59
|
+
"plt.plot(history.history['val_accuracy'])\n",
|
60
|
+
"plt.title('model accuracy')\n",
|
61
|
+
"plt.ylabel('accuracy')\n",
|
62
|
+
"plt.xlabel('epoch')\n",
|
63
|
+
"plt.legend(['train', 'test'], loc='upper left')\n",
|
64
|
+
"plt.show()\n",
|
65
|
+
"plt.plot(history.history['loss'])\n",
|
66
|
+
"plt.plot(history.history['val_loss'])\n",
|
67
|
+
"plt.title('model loss')\n",
|
68
|
+
"plt.ylabel('loss')\n",
|
69
|
+
"plt.xlabel('epoch')\n",
|
70
|
+
"plt.legend(['train', 'test'], loc='upper left')\n",
|
71
|
+
"plt.show()"
|
72
|
+
]
|
73
|
+
}
|
74
|
+
],
|
75
|
+
"metadata": {
|
76
|
+
"colab": {
|
77
|
+
"authorship_tag": "ABX9TyN/7SS5L3TgMPgTzruMIL5B",
|
78
|
+
"provenance": []
|
79
|
+
},
|
80
|
+
"kernelspec": {
|
81
|
+
"display_name": "Python 3 (ipykernel)",
|
82
|
+
"language": "python",
|
83
|
+
"name": "python3"
|
84
|
+
},
|
85
|
+
"language_info": {
|
86
|
+
"codemirror_mode": {
|
87
|
+
"name": "ipython",
|
88
|
+
"version": 3
|
89
|
+
},
|
90
|
+
"file_extension": ".py",
|
91
|
+
"mimetype": "text/x-python",
|
92
|
+
"name": "python",
|
93
|
+
"nbconvert_exporter": "python",
|
94
|
+
"pygments_lexer": "ipython3",
|
95
|
+
"version": "3.12.4"
|
96
|
+
}
|
97
|
+
},
|
98
|
+
"nbformat": 4,
|
99
|
+
"nbformat_minor": 4
|
100
|
+
}
|