noshot 6.0.0__py3-none-any.whl → 7.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/Rolls Royce AllinOne.ipynb +691 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/1. EDA-PCA (Balance Scale Dataset).ipynb +147 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/1. EDA-PCA (Rice Dataset).ipynb +181 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/10. HMM Veterbi.ipynb +152 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Balance Scale Dataset).ipynb +117 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Iris Dataset).ipynb +156 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Sobar-72 Dataset).ipynb +215 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/3. LDA (Balance Scale Dataset).ipynb +78 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/3. LDA (NPHA Doctor Visits Dataset).ipynb +114 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/4. Linear Regression (Machine Dataset).ipynb +115 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/4. Linear Regression (Real Estate Dataset).ipynb +146 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/5. Logistic Regression (Magic04 Dataset).ipynb +130 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/5. Logistic Regression (Wine Dataset).ipynb +112 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +118 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/6. Naive Bayes Classifier (Wine Dataset).ipynb +89 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/7. SVM (Rice Dataset).ipynb +120 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/8. FeedForward NN (Sobar72 Dataset).ipynb +262 -0
- noshot/data/ML TS XAI/ML/Tamilan Code/9. CNN (Cifar10 Dataset).ipynb +156 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/1. PCA.ipynb +162 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/10. CNN.ipynb +100 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/11. HMM.ipynb +336 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/2. KNN.ipynb +149 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/3. LDA.ipynb +132 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/4. Linear Regression.ipynb +86 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/5. Logistic Regression.ipynb +115 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/6. Naive Bayes (Titanic).ipynb +196 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/6. Naive Bayes (Wine).ipynb +98 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/7. SVM Linear.ipynb +109 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/8. SVM Non-Linear.ipynb +195 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/9. FNN With Regularization.ipynb +189 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/9. FNN Without Regularization.ipynb +197 -0
- noshot/data/ML TS XAI/ML/Whitefang Code/All in One Lab CIA 1 Q.ipynb +1087 -0
- {noshot-6.0.0.dist-info → noshot-7.0.0.dist-info}/METADATA +1 -1
- noshot-7.0.0.dist-info/RECORD +41 -0
- {noshot-6.0.0.dist-info → noshot-7.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-7.0.0.dist-info}/licenses/LICENSE.txt +0 -0
- {noshot-6.0.0.dist-info → noshot-7.0.0.dist-info}/top_level.txt +0 -0
@@ -1,206 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"cells": [
|
3
|
-
{
|
4
|
-
"cell_type": "raw",
|
5
|
-
"metadata": {},
|
6
|
-
"source": [
|
7
|
-
"1.\t Train a Convolutional Neural Network (CNN) on the CIFAR-10 dataset. Then, apply Grad-CAM and Saliency Map techniques to visualize and interpret the model’s predictions.\n",
|
8
|
-
"\n",
|
9
|
-
"from tensorflow.keras.datasets import cifar10\n",
|
10
|
-
"# Load the dataset\n",
|
11
|
-
"(x_train, y_train), (x_test, y_test) = cifar10.load_data()\n",
|
12
|
-
"\n",
|
13
|
-
"3.\tPerform a SHAP -based explanation for an image classification model using the SHAP model. \n",
|
14
|
-
"Use the following dataset\n",
|
15
|
-
"from tensorflow.keras.datasets import mnist\n",
|
16
|
-
"# Loads the MNIST dataset\n",
|
17
|
-
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n"
|
18
|
-
]
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"cell_type": "code",
|
22
|
-
"execution_count": null,
|
23
|
-
"metadata": {
|
24
|
-
"colab": {
|
25
|
-
"base_uri": "https://localhost:8080/",
|
26
|
-
"height": 1000
|
27
|
-
},
|
28
|
-
"id": "ZsDuI4okVUFU",
|
29
|
-
"outputId": "9422b070-b240-4f9d-e3d3-c8f211f15c4a"
|
30
|
-
},
|
31
|
-
"outputs": [],
|
32
|
-
"source": [
|
33
|
-
"# Step 1: Install TensorFlow (if not already installed)\n",
|
34
|
-
"\n",
|
35
|
-
"# Step 2: Import Libraries\n",
|
36
|
-
"import numpy as np\n",
|
37
|
-
"import matplotlib.pyplot as plt\n",
|
38
|
-
"import tensorflow as tf\n",
|
39
|
-
"from tensorflow.keras.datasets import cifar10\n",
|
40
|
-
"from tensorflow.keras.utils import to_categorical\n",
|
41
|
-
"from tensorflow.keras import Input, Model\n",
|
42
|
-
"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\n",
|
43
|
-
"import warnings\n",
|
44
|
-
"warnings.filterwarnings('ignore')\n",
|
45
|
-
"\n",
|
46
|
-
"# Step 3: Load and Preprocess CIFAR-10 Data\n",
|
47
|
-
"(x_train, y_train), (x_test, y_test) = cifar10.load_data()\n",
|
48
|
-
"x_train, x_test = x_train / 255.0, x_test / 255.0\n",
|
49
|
-
"y_train_cat = to_categorical(y_train, 10)\n",
|
50
|
-
"y_test_cat = to_categorical(y_test, 10)\n",
|
51
|
-
"\n",
|
52
|
-
"# Step 4: Define Model using Functional API\n",
|
53
|
-
"inputs = Input(shape=(32, 32, 3))\n",
|
54
|
-
"x = Conv2D(32, (3, 3), activation='relu', name='conv1')(inputs)\n",
|
55
|
-
"x = MaxPooling2D((2, 2))(x)\n",
|
56
|
-
"x = Conv2D(64, (3, 3), activation='relu', name='conv2')(x)\n",
|
57
|
-
"x = MaxPooling2D((2, 2))(x)\n",
|
58
|
-
"x = Flatten()(x)\n",
|
59
|
-
"x = Dense(64, activation='relu')(x)\n",
|
60
|
-
"x = Dropout(0.5)(x)\n",
|
61
|
-
"outputs = Dense(10, activation='softmax')(x)\n",
|
62
|
-
"\n",
|
63
|
-
"model = Model(inputs=inputs, outputs=outputs)\n",
|
64
|
-
"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
65
|
-
"\n",
|
66
|
-
"# Step 5: Train the Model\n",
|
67
|
-
"model.fit(x_train, y_train_cat, epochs=3, validation_split=0.2)\n",
|
68
|
-
"\n",
|
69
|
-
"# Step 6: Grad-CAM Visualization\n",
|
70
|
-
"img = x_test[1]\n",
|
71
|
-
"img_tensor = tf.expand_dims(img, axis=0)\n",
|
72
|
-
"\n",
|
73
|
-
"# Predict once to build model\n",
|
74
|
-
"_ = model.predict(img_tensor)\n",
|
75
|
-
"\n",
|
76
|
-
"# Create Grad-CAM model\n",
|
77
|
-
"grad_model = tf.keras.models.Model(\n",
|
78
|
-
" [model.inputs],\n",
|
79
|
-
" [model.get_layer('conv2').output, model.output]\n",
|
80
|
-
")\n",
|
81
|
-
"\n",
|
82
|
-
"# Compute Gradients\n",
|
83
|
-
"with tf.GradientTape() as tape:\n",
|
84
|
-
" conv_outputs, predictions = grad_model(img_tensor)\n",
|
85
|
-
" pred_class = tf.argmax(predictions[0])\n",
|
86
|
-
" loss = predictions[:, pred_class]\n",
|
87
|
-
"\n",
|
88
|
-
"grads = tape.gradient(loss, conv_outputs)\n",
|
89
|
-
"pooled_grads = tf.reduce_mean(grads, axis=(0, 1, 2))\n",
|
90
|
-
"\n",
|
91
|
-
"# Generate Heatmap\n",
|
92
|
-
"heatmap = tf.reduce_sum(tf.multiply(pooled_grads, conv_outputs), axis=-1)[0]\n",
|
93
|
-
"heatmap = np.maximum(heatmap, 0) / np.max(heatmap)\n",
|
94
|
-
"\n",
|
95
|
-
"# Show Grad-CAM\n",
|
96
|
-
"plt.imshow(img)\n",
|
97
|
-
"plt.imshow(heatmap, cmap='jet', alpha=0.5)\n",
|
98
|
-
"plt.axis('off')\n",
|
99
|
-
"plt.title('Grad-CAM')\n",
|
100
|
-
"plt.show()\n",
|
101
|
-
"\n",
|
102
|
-
"# Step 7: Saliency Map\n",
|
103
|
-
"img_tensor = tf.convert_to_tensor(img_tensor)\n",
|
104
|
-
"\n",
|
105
|
-
"with tf.GradientTape() as tape:\n",
|
106
|
-
" tape.watch(img_tensor)\n",
|
107
|
-
" predictions = model(img_tensor)\n",
|
108
|
-
" loss = predictions[:, pred_class]\n",
|
109
|
-
"\n",
|
110
|
-
"grads = tape.gradient(loss, img_tensor)[0]\n",
|
111
|
-
"saliency = np.max(np.abs(grads), axis=-1)\n",
|
112
|
-
"\n",
|
113
|
-
"# Show Saliency Map\n",
|
114
|
-
"plt.imshow(saliency, cmap='hot')\n",
|
115
|
-
"plt.axis('off')\n",
|
116
|
-
"plt.title('Saliency Map')\n",
|
117
|
-
"plt.show()\n"
|
118
|
-
]
|
119
|
-
},
|
120
|
-
{
|
121
|
-
"cell_type": "code",
|
122
|
-
"execution_count": null,
|
123
|
-
"metadata": {
|
124
|
-
"colab": {
|
125
|
-
"base_uri": "https://localhost:8080/",
|
126
|
-
"height": 1000
|
127
|
-
},
|
128
|
-
"id": "E6DueKo2e1PX",
|
129
|
-
"outputId": "edfc534c-90af-4e4e-9479-4147cc974474"
|
130
|
-
},
|
131
|
-
"outputs": [],
|
132
|
-
"source": [
|
133
|
-
"import numpy as np\n",
|
134
|
-
"import tensorflow as tf\n",
|
135
|
-
"import shap\n",
|
136
|
-
"import matplotlib.pyplot as plt\n",
|
137
|
-
"\n",
|
138
|
-
"# Load and preprocess MNIST data\n",
|
139
|
-
"from tensorflow.keras.datasets import mnist\n",
|
140
|
-
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
|
141
|
-
"\n",
|
142
|
-
"# Normalize and reshape data\n",
|
143
|
-
"x_train = x_train / 255.0\n",
|
144
|
-
"x_test = x_test / 255.0\n",
|
145
|
-
"x_train = np.expand_dims(x_train, -1)\n",
|
146
|
-
"x_test = np.expand_dims(x_test, -1)\n",
|
147
|
-
"\n",
|
148
|
-
"# Define a simple CNN model\n",
|
149
|
-
"model = tf.keras.models.Sequential([\n",
|
150
|
-
" tf.keras.layers.Conv2D(16, (3, 3), activation='relu', input_shape=(28, 28, 1)),\n",
|
151
|
-
" tf.keras.layers.MaxPooling2D((2, 2)),\n",
|
152
|
-
" tf.keras.layers.Flatten(),\n",
|
153
|
-
" tf.keras.layers.Dense(64, activation='relu'),\n",
|
154
|
-
" tf.keras.layers.Dense(10, activation='softmax')\n",
|
155
|
-
"])\n",
|
156
|
-
"\n",
|
157
|
-
"# Compile the model\n",
|
158
|
-
"model.compile(optimizer='adam',\n",
|
159
|
-
" loss='sparse_categorical_crossentropy',\n",
|
160
|
-
" metrics=['accuracy'])\n",
|
161
|
-
"\n",
|
162
|
-
"# Train the model\n",
|
163
|
-
"model.fit(x_train, y_train, epochs=3, batch_size=128, validation_split=0.1)\n",
|
164
|
-
"\n",
|
165
|
-
"# Prepare SHAP explainer\n",
|
166
|
-
"background = x_train[np.random.choice(x_train.shape[0], 100, replace=False)]\n",
|
167
|
-
"\n",
|
168
|
-
"# Wrap the model prediction function\n",
|
169
|
-
"explainer = shap.GradientExplainer(model, background)\n",
|
170
|
-
"\n",
|
171
|
-
"# Select a few test samples for explanation\n",
|
172
|
-
"test_images = x_test[:10]\n",
|
173
|
-
"\n",
|
174
|
-
"# Compute SHAP values\n",
|
175
|
-
"shap_values = explainer.shap_values(test_images)\n",
|
176
|
-
"\n",
|
177
|
-
"# Visualize SHAP values\n",
|
178
|
-
"shap.image_plot(shap_values, test_images)\n"
|
179
|
-
]
|
180
|
-
}
|
181
|
-
],
|
182
|
-
"metadata": {
|
183
|
-
"colab": {
|
184
|
-
"provenance": []
|
185
|
-
},
|
186
|
-
"kernelspec": {
|
187
|
-
"display_name": "Python 3 (ipykernel)",
|
188
|
-
"language": "python",
|
189
|
-
"name": "python3"
|
190
|
-
},
|
191
|
-
"language_info": {
|
192
|
-
"codemirror_mode": {
|
193
|
-
"name": "ipython",
|
194
|
-
"version": 3
|
195
|
-
},
|
196
|
-
"file_extension": ".py",
|
197
|
-
"mimetype": "text/x-python",
|
198
|
-
"name": "python",
|
199
|
-
"nbconvert_exporter": "python",
|
200
|
-
"pygments_lexer": "ipython3",
|
201
|
-
"version": "3.12.4"
|
202
|
-
}
|
203
|
-
},
|
204
|
-
"nbformat": 4,
|
205
|
-
"nbformat_minor": 4
|
206
|
-
}
|