noshot 5.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.
Files changed (43) hide show
  1. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +691 -0
  2. noshot/data/ML TS XAI/ML/Tamilan Code/1. EDA-PCA (Balance Scale Dataset).ipynb +147 -0
  3. noshot/data/ML TS XAI/ML/Tamilan Code/1. EDA-PCA (Rice Dataset).ipynb +181 -0
  4. noshot/data/ML TS XAI/ML/Tamilan Code/10. HMM Veterbi.ipynb +152 -0
  5. noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Balance Scale Dataset).ipynb +117 -0
  6. noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Iris Dataset).ipynb +156 -0
  7. noshot/data/ML TS XAI/ML/Tamilan Code/2. KNN (Sobar-72 Dataset).ipynb +215 -0
  8. noshot/data/ML TS XAI/ML/Tamilan Code/3. LDA (Balance Scale Dataset).ipynb +78 -0
  9. noshot/data/ML TS XAI/ML/Tamilan Code/3. LDA (NPHA Doctor Visits Dataset).ipynb +114 -0
  10. noshot/data/ML TS XAI/ML/Tamilan Code/4. Linear Regression (Machine Dataset).ipynb +115 -0
  11. noshot/data/ML TS XAI/ML/Tamilan Code/4. Linear Regression (Real Estate Dataset).ipynb +146 -0
  12. noshot/data/ML TS XAI/ML/Tamilan Code/5. Logistic Regression (Magic04 Dataset).ipynb +130 -0
  13. noshot/data/ML TS XAI/ML/Tamilan Code/5. Logistic Regression (Wine Dataset).ipynb +112 -0
  14. noshot/data/ML TS XAI/ML/Tamilan Code/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +118 -0
  15. noshot/data/ML TS XAI/ML/Tamilan Code/6. Naive Bayes Classifier (Wine Dataset).ipynb +89 -0
  16. noshot/data/ML TS XAI/ML/Tamilan Code/7. SVM (Rice Dataset).ipynb +120 -0
  17. noshot/data/ML TS XAI/ML/Tamilan Code/8. FeedForward NN (Sobar72 Dataset).ipynb +262 -0
  18. noshot/data/ML TS XAI/ML/Tamilan Code/9. CNN (Cifar10 Dataset).ipynb +156 -0
  19. noshot/data/ML TS XAI/ML/Whitefang Code/1. PCA.ipynb +162 -0
  20. noshot/data/ML TS XAI/ML/Whitefang Code/10. CNN.ipynb +100 -0
  21. noshot/data/ML TS XAI/ML/Whitefang Code/11. HMM.ipynb +336 -0
  22. noshot/data/ML TS XAI/ML/Whitefang Code/2. KNN.ipynb +149 -0
  23. noshot/data/ML TS XAI/ML/Whitefang Code/3. LDA.ipynb +132 -0
  24. noshot/data/ML TS XAI/ML/Whitefang Code/4. Linear Regression.ipynb +86 -0
  25. noshot/data/ML TS XAI/ML/Whitefang Code/5. Logistic Regression.ipynb +115 -0
  26. noshot/data/ML TS XAI/ML/Whitefang Code/6. Naive Bayes (Titanic).ipynb +196 -0
  27. noshot/data/ML TS XAI/ML/Whitefang Code/6. Naive Bayes (Wine).ipynb +98 -0
  28. noshot/data/ML TS XAI/ML/Whitefang Code/7. SVM Linear.ipynb +109 -0
  29. noshot/data/ML TS XAI/ML/Whitefang Code/8. SVM Non-Linear.ipynb +195 -0
  30. noshot/data/ML TS XAI/ML/Whitefang Code/9. FNN With Regularization.ipynb +189 -0
  31. noshot/data/ML TS XAI/ML/Whitefang Code/9. FNN Without Regularization.ipynb +197 -0
  32. noshot/data/ML TS XAI/ML/Whitefang Code/All in One Lab CIA 1 Q.ipynb +1087 -0
  33. {noshot-5.0.0.dist-info → noshot-7.0.0.dist-info}/METADATA +1 -1
  34. noshot-7.0.0.dist-info/RECORD +41 -0
  35. {noshot-5.0.0.dist-info → noshot-7.0.0.dist-info}/WHEEL +1 -1
  36. noshot/data/ML TS XAI/XAI/Q1.ipynb +0 -535
  37. noshot/data/ML TS XAI/XAI/Q2.ipynb +0 -38129
  38. noshot/data/ML TS XAI/XAI/Q3.ipynb +0 -1340
  39. noshot/data/ML TS XAI/XAI/Q4.ipynb +0 -246
  40. noshot/data/ML TS XAI/XAI/Q5.ipynb +0 -2450
  41. noshot-5.0.0.dist-info/RECORD +0 -14
  42. {noshot-5.0.0.dist-info → noshot-7.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  43. {noshot-5.0.0.dist-info → noshot-7.0.0.dist-info}/top_level.txt +0 -0
@@ -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
+ }
@@ -0,0 +1,336 @@
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": 4740,
13
+ "status": "ok",
14
+ "timestamp": 1745300903286,
15
+ "user": {
16
+ "displayName": "Jaison A",
17
+ "userId": "07006398627763032071"
18
+ },
19
+ "user_tz": -330
20
+ },
21
+ "id": "4a-KUub89a-f",
22
+ "outputId": "b5058ef1-2acb-4100-d6c5-3f8fd8662e2e"
23
+ },
24
+ "outputs": [],
25
+ "source": [
26
+ "import numpy as np\n",
27
+ "import pandas as pd\n",
28
+ "import networkx.drawing.nx_pydot as gl\n",
29
+ "import networkx as nx\n",
30
+ "import matplotlib.pyplot as plt\n",
31
+ "from pprint import pprint\n",
32
+ "states = ['O1', 'O2', 'O3']\n",
33
+ "pi = [0.25, 0.4, 0.35]\n",
34
+ "state_space = pd.Series(pi, index=states, name='states')\n",
35
+ "print(state_space)\n",
36
+ "print(state_space.sum())\n",
37
+ "q_df = pd.DataFrame(columns=states, index=states)\n",
38
+ "q_df.loc[states[0]] = [0.4, 0.2, 0.4]\n",
39
+ "q_df.loc[states[1]] = [0.45, 0.45, 0.1]\n",
40
+ "q_df.loc[states[2]] = [0.45, 0.25, .3]\n",
41
+ "print(q_df)\n",
42
+ "q = q_df.values\n",
43
+ "#print('\\n')\n",
44
+ "print(q, q.shape)\n",
45
+ "print('\\n')\n",
46
+ "print(q_df.sum(axis=1))\n",
47
+ "from pprint import pprint\n",
48
+ "\n",
49
+ "def _get_markov_edges(Q):\n",
50
+ " edges = {}\n",
51
+ " for col in Q.columns:\n",
52
+ " for idx in Q.index:\n",
53
+ " edges[(idx,col)] = Q.loc[idx,col]\n",
54
+ " return edges\n",
55
+ "edges_wts = _get_markov_edges(q_df)\n",
56
+ "pprint(edges_wts)\n",
57
+ "G = nx.MultiDiGraph()\n",
58
+ "# nodes correspond to states\n",
59
+ "G.add_nodes_from(states)\n",
60
+ "print('Nodes:\\n')\n",
61
+ "print(G.nodes())\n",
62
+ "print('\\n')\n",
63
+ "for k, v in edges_wts.items():\n",
64
+ " tmp_origin, tmp_destination = k[0], k[1]\n",
65
+ " G.add_edge(tmp_origin, tmp_destination, weight=v, label=v)\n",
66
+ "print('Edges:')\n",
67
+ "pprint(G.edges(data=True))\n",
68
+ "pos = nx.drawing.nx_pydot.graphviz_layout(G, prog='dot')\n",
69
+ "nx.draw_networkx(G, pos)\n",
70
+ "hidden_states = ['S1', 'S2']\n",
71
+ "pi = [0.5, 0.5]\n",
72
+ "print('\\n')\n",
73
+ "state_space = pd.Series(pi, index=hidden_states, name='states')\n",
74
+ "print(state_space)\n",
75
+ "print('\\n')\n",
76
+ "print(state_space.sum())\n",
77
+ "a_df = pd.DataFrame(columns=hidden_states, index=hidden_states)\n",
78
+ "a_df.loc[hidden_states[0]] = [0.7, 0.3]\n",
79
+ "a_df.loc[hidden_states[1]] = [0.4, 0.6]\n",
80
+ "print(a_df)\n",
81
+ "a = a_df.values\n",
82
+ "print('\\n')\n",
83
+ "print(a)\n",
84
+ "print(a.shape)\n",
85
+ "print('\\n')\n",
86
+ "print(a_df.sum(axis=1))\n",
87
+ "observable_states = states\n",
88
+ "b_df = pd.DataFrame(columns=observable_states, index=hidden_states)\n",
89
+ "b_df.loc[hidden_states[0]] = [0.2, 0.6, 0.2]\n",
90
+ "b_df.loc[hidden_states[1]] = [0.4, 0.1, 0.5]\n",
91
+ "print(b_df)\n",
92
+ "\n",
93
+ "b = b_df.values\n",
94
+ "print('\\n')\n",
95
+ "print(b)\n",
96
+ "print(b.shape)\n",
97
+ "print('\\n')\n",
98
+ "print(b_df.sum(axis=1))\n",
99
+ "hide_edges_wts = _get_markov_edges(a_df)\n",
100
+ "pprint(hide_edges_wts)\n",
101
+ "emit_edges_wts = _get_markov_edges(b_df)\n",
102
+ "pprint(emit_edges_wts)\n",
103
+ "G = nx.MultiDiGraph()\n",
104
+ "G.add_nodes_from(hidden_states)\n",
105
+ "print('Nodes:\\n')\n",
106
+ "print(G.nodes())\n",
107
+ "print('\\n')\n",
108
+ "pos = nx.drawing.nx_pydot.graphviz_layout(G, prog='neato')\n",
109
+ "nx.draw_networkx(G, pos)\n",
110
+ "plt.show()\n",
111
+ "state_map = {0:'S1', 1:'S2'}\n",
112
+ "path=[0,1,0]\n",
113
+ "state_path = [state_map[v] for v in path]\n",
114
+ "obs_seq=['O1','O3','O2']\n",
115
+ "result = (pd.DataFrame().assign(Observation=obs_seq).assign(Best_Path=state_path))\n",
116
+ "print(result)"
117
+ ]
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "execution_count": null,
122
+ "metadata": {
123
+ "colab": {
124
+ "base_uri": "https://localhost:8080/",
125
+ "height": 1000
126
+ },
127
+ "executionInfo": {
128
+ "elapsed": 2283,
129
+ "status": "ok",
130
+ "timestamp": 1745300905577,
131
+ "user": {
132
+ "displayName": "Jaison A",
133
+ "userId": "07006398627763032071"
134
+ },
135
+ "user_tz": -330
136
+ },
137
+ "id": "9tVvFPx4A4PN",
138
+ "outputId": "7c0549b9-bb15-450d-ee72-45bec5c8811c"
139
+ },
140
+ "outputs": [],
141
+ "source": [
142
+ "import numpy as np\n",
143
+ "import pandas as pd\n",
144
+ "import networkx as nx\n",
145
+ "import matplotlib.pyplot as plt\n",
146
+ "from pprint import pprint\n",
147
+ "\n",
148
+ "# ====================\n",
149
+ "# 1. Define the HMM parameters\n",
150
+ "# ====================\n",
151
+ "\n",
152
+ "# Observable states\n",
153
+ "states = ['O1', 'O2', 'O3']\n",
154
+ "pi = [0.25, 0.4, 0.35]\n",
155
+ "state_space = pd.Series(pi, index=states, name='states')\n",
156
+ "print(\"Initial State Probabilities:\")\n",
157
+ "print(state_space)\n",
158
+ "print(\"Sum:\", state_space.sum())\n",
159
+ "print(\"\\n\")\n",
160
+ "\n",
161
+ "# Transition matrix for observable states\n",
162
+ "q_df = pd.DataFrame(columns=states, index=states)\n",
163
+ "q_df.loc[states[0]] = [0.4, 0.2, 0.4]\n",
164
+ "q_df.loc[states[1]] = [0.45, 0.45, 0.1]\n",
165
+ "q_df.loc[states[2]] = [0.45, 0.25, 0.3]\n",
166
+ "print(\"Transition Matrix (Observable States):\")\n",
167
+ "print(q_df)\n",
168
+ "print(\"\\nRow Sums:\")\n",
169
+ "print(q_df.sum(axis=1))\n",
170
+ "print(\"\\n\")\n",
171
+ "\n",
172
+ "# ====================\n",
173
+ "# 2. Visualization of observable state transitions\n",
174
+ "# ====================\n",
175
+ "\n",
176
+ "def _get_markov_edges(Q):\n",
177
+ " edges = {}\n",
178
+ " for col in Q.columns:\n",
179
+ " for idx in Q.index:\n",
180
+ " edges[(idx, col)] = Q.loc[idx, col]\n",
181
+ " return edges\n",
182
+ "\n",
183
+ "edges_wts = _get_markov_edges(q_df)\n",
184
+ "print(\"Edge Weights:\")\n",
185
+ "pprint(edges_wts)\n",
186
+ "\n",
187
+ "G = nx.MultiDiGraph()\n",
188
+ "G.add_nodes_from(states)\n",
189
+ "print('\\nNodes:')\n",
190
+ "print(G.nodes())\n",
191
+ "\n",
192
+ "for k, v in edges_wts.items():\n",
193
+ " tmp_origin, tmp_destination = k[0], k[1]\n",
194
+ " G.add_edge(tmp_origin, tmp_destination, weight=v, label=v)\n",
195
+ "\n",
196
+ "print('\\nEdges:')\n",
197
+ "pprint(G.edges(data=True))\n",
198
+ "\n",
199
+ "pos = nx.drawing.nx_pydot.graphviz_layout(G, prog='dot')\n",
200
+ "nx.draw_networkx(G, pos, with_labels=True, node_size=1000,\n",
201
+ " node_color='skyblue', font_size=12, arrows=True)\n",
202
+ "edge_labels = nx.get_edge_attributes(G, 'label')\n",
203
+ "nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)\n",
204
+ "plt.title(\"Observable State Transitions\")\n",
205
+ "plt.show()\n",
206
+ "\n",
207
+ "# ====================\n",
208
+ "# 3. Hidden States and their parameters\n",
209
+ "# ====================\n",
210
+ "\n",
211
+ "hidden_states = ['S1', 'S2']\n",
212
+ "pi = [0.5, 0.5]\n",
213
+ "state_space = pd.Series(pi, index=hidden_states, name='states')\n",
214
+ "print(\"\\nHidden State Probabilities:\")\n",
215
+ "print(state_space)\n",
216
+ "print(\"Sum:\", state_space.sum())\n",
217
+ "print(\"\\n\")\n",
218
+ "\n",
219
+ "# Transition matrix for hidden states\n",
220
+ "a_df = pd.DataFrame(columns=hidden_states, index=hidden_states)\n",
221
+ "a_df.loc[hidden_states[0]] = [0.7, 0.3]\n",
222
+ "a_df.loc[hidden_states[1]] = [0.4, 0.6]\n",
223
+ "print(\"Transition Matrix (Hidden States):\")\n",
224
+ "print(a_df)\n",
225
+ "print(\"\\nRow Sums:\")\n",
226
+ "print(a_df.sum(axis=1))\n",
227
+ "print(\"\\n\")\n",
228
+ "\n",
229
+ "# Emission probabilities\n",
230
+ "observable_states = states\n",
231
+ "b_df = pd.DataFrame(columns=observable_states, index=hidden_states)\n",
232
+ "b_df.loc[hidden_states[0]] = [0.2, 0.6, 0.2]\n",
233
+ "b_df.loc[hidden_states[1]] = [0.4, 0.1, 0.5]\n",
234
+ "print(\"Emission Probabilities:\")\n",
235
+ "print(b_df)\n",
236
+ "print(\"\\nRow Sums:\")\n",
237
+ "print(b_df.sum(axis=1))\n",
238
+ "print(\"\\n\")\n",
239
+ "\n",
240
+ "# ====================\n",
241
+ "# 4. Visualization of hidden state transitions and emissions\n",
242
+ "# ====================\n",
243
+ "\n",
244
+ "hide_edges_wts = _get_markov_edges(a_df)\n",
245
+ "print(\"Hidden State Transition Weights:\")\n",
246
+ "pprint(hide_edges_wts)\n",
247
+ "\n",
248
+ "emit_edges_wts = _get_markov_edges(b_df)\n",
249
+ "print(\"\\nEmission Weights:\")\n",
250
+ "pprint(emit_edges_wts)\n",
251
+ "\n",
252
+ "# Hidden state transitions graph\n",
253
+ "G_hidden = nx.MultiDiGraph()\n",
254
+ "G_hidden.add_nodes_from(hidden_states)\n",
255
+ "print('\\nHidden State Nodes:')\n",
256
+ "print(G_hidden.nodes())\n",
257
+ "\n",
258
+ "for k, v in hide_edges_wts.items():\n",
259
+ " tmp_origin, tmp_destination = k[0], k[1]\n",
260
+ " G_hidden.add_edge(tmp_origin, tmp_destination, weight=v, label=v)\n",
261
+ "\n",
262
+ "pos = nx.drawing.nx_pydot.graphviz_layout(G_hidden, prog='dot')\n",
263
+ "nx.draw_networkx(G_hidden, pos, with_labels=True, node_size=1000,\n",
264
+ " node_color='lightgreen', font_size=12, arrows=True)\n",
265
+ "edge_labels = nx.get_edge_attributes(G_hidden, 'label')\n",
266
+ "nx.draw_networkx_edge_labels(G_hidden, pos, edge_labels=edge_labels)\n",
267
+ "plt.title(\"Hidden State Transitions\")\n",
268
+ "plt.show()\n",
269
+ "\n",
270
+ "# Emission probabilities graph\n",
271
+ "G_emit = nx.MultiDiGraph()\n",
272
+ "G_emit.add_nodes_from(hidden_states)\n",
273
+ "print('\\nEmission Nodes:')\n",
274
+ "print(G_emit.nodes())\n",
275
+ "\n",
276
+ "for k, v in emit_edges_wts.items():\n",
277
+ " tmp_origin, tmp_destination = k[0], k[1]\n",
278
+ " G_emit.add_edge(tmp_origin, tmp_destination, weight=v, label=v)\n",
279
+ "\n",
280
+ "pos = nx.drawing.nx_pydot.graphviz_layout(G_emit, prog='neato')\n",
281
+ "nx.draw_networkx(G_emit, pos, with_labels=True, node_size=1000,\n",
282
+ " node_color='lightcoral', font_size=12, arrows=True)\n",
283
+ "edge_labels = nx.get_edge_attributes(G_emit, 'label')\n",
284
+ "nx.draw_networkx_edge_labels(G_emit, pos, edge_labels=edge_labels)\n",
285
+ "plt.title(\"Emission Probabilities\")\n",
286
+ "plt.show()\n",
287
+ "\n",
288
+ "# ====================\n",
289
+ "# 5. Sample Observation Sequence and State Path\n",
290
+ "# ====================\n",
291
+ "\n",
292
+ "# Sample data (as shown in the lab manual output)\n",
293
+ "obs_seq = ['O2', 'O2', 'O3', 'O2', 'O1', 'O2', 'O3', 'O2', 'O1', 'O3', 'O3', 'O1', 'O2', 'O1', 'O2']\n",
294
+ "path = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0] # 0=S1, 1=S2\n",
295
+ "\n",
296
+ "state_map = {0:'S1', 1:'S2'}\n",
297
+ "state_path = [state_map[v] for v in path]\n",
298
+ "\n",
299
+ "result = pd.DataFrame({\n",
300
+ " 'Observation': obs_seq,\n",
301
+ " 'Best_Path': state_path\n",
302
+ "})\n",
303
+ "\n",
304
+ "print(\"\\nObservation Sequence with Most Likely Hidden States:\")\n",
305
+ "print(result)"
306
+ ]
307
+ }
308
+ ],
309
+ "metadata": {
310
+ "accelerator": "GPU",
311
+ "colab": {
312
+ "authorship_tag": "ABX9TyMGDLt9IOT6gGXDCsIPtxky",
313
+ "gpuType": "T4",
314
+ "provenance": []
315
+ },
316
+ "kernelspec": {
317
+ "display_name": "Python 3 (ipykernel)",
318
+ "language": "python",
319
+ "name": "python3"
320
+ },
321
+ "language_info": {
322
+ "codemirror_mode": {
323
+ "name": "ipython",
324
+ "version": 3
325
+ },
326
+ "file_extension": ".py",
327
+ "mimetype": "text/x-python",
328
+ "name": "python",
329
+ "nbconvert_exporter": "python",
330
+ "pygments_lexer": "ipython3",
331
+ "version": "3.12.4"
332
+ }
333
+ },
334
+ "nbformat": 4,
335
+ "nbformat_minor": 4
336
+ }
@@ -0,0 +1,149 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {
7
+ "executionInfo": {
8
+ "elapsed": 9,
9
+ "status": "ok",
10
+ "timestamp": 1740322226638,
11
+ "user": {
12
+ "displayName": "Jaison A",
13
+ "userId": "07006398627763032071"
14
+ },
15
+ "user_tz": -330
16
+ },
17
+ "id": "bbUA3qg5SCrE"
18
+ },
19
+ "outputs": [],
20
+ "source": [
21
+ "import pandas as pd\n",
22
+ "from sklearn.preprocessing import StandardScaler\n",
23
+ "from sklearn.neighbors import KNeighborsClassifier\n",
24
+ "from sklearn.model_selection import train_test_split\n",
25
+ "from sklearn.metrics import accuracy_score,classification_report"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": null,
31
+ "metadata": {
32
+ "colab": {
33
+ "base_uri": "https://localhost:8080/",
34
+ "height": 327
35
+ },
36
+ "executionInfo": {
37
+ "elapsed": 97,
38
+ "status": "ok",
39
+ "timestamp": 1740322228224,
40
+ "user": {
41
+ "displayName": "Jaison A",
42
+ "userId": "07006398627763032071"
43
+ },
44
+ "user_tz": -330
45
+ },
46
+ "id": "hNhWJ01kSF2W",
47
+ "outputId": "9a86b0be-6836-4b37-9ed9-1e8593126884"
48
+ },
49
+ "outputs": [],
50
+ "source": [
51
+ "data2=pd.read_csv('/content/dataset2.csv',names=['Class name','Left weight','Left distance','Right weight','Right distance'])\n",
52
+ "display(data2.head())\n",
53
+ "\n",
54
+ "x=data2.loc[:,['Left weight','Left distance','Right weight','Right distance']] #input features.\n",
55
+ "y=data2.loc[:,'Class name'] #output feature.\n",
56
+ "\n",
57
+ "Standardized_x=StandardScaler().fit_transform(x)#statndardize the dataset.\n",
58
+ "display(Standardized_x)\n",
59
+ "\n",
60
+ "X_train,X_test,y_train,y_test=train_test_split(Standardized_x,y,test_size=0.4,random_state=4)#split data for training and prediction.\n"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": null,
66
+ "metadata": {
67
+ "colab": {
68
+ "base_uri": "https://localhost:8080/"
69
+ },
70
+ "executionInfo": {
71
+ "elapsed": 17,
72
+ "status": "ok",
73
+ "timestamp": 1740322230944,
74
+ "user": {
75
+ "displayName": "Jaison A",
76
+ "userId": "07006398627763032071"
77
+ },
78
+ "user_tz": -330
79
+ },
80
+ "id": "7eEwp2cZSI8M",
81
+ "outputId": "3f03a6b2-b582-4d6b-abbb-5fd695636f71"
82
+ },
83
+ "outputs": [],
84
+ "source": [
85
+ "# shape of each terms.\n",
86
+ "\n",
87
+ "print(\"Shape of X_train : \",X_train.shape)\n",
88
+ "print(\"Shape of y_train : \",y_train.shape)\n",
89
+ "print(\"Shape of X_test : \",X_test.shape)\n",
90
+ "print(\"Shape of y_test : \",y_test.shape)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "metadata": {
97
+ "colab": {
98
+ "base_uri": "https://localhost:8080/"
99
+ },
100
+ "executionInfo": {
101
+ "elapsed": 11,
102
+ "status": "ok",
103
+ "timestamp": 1740322232987,
104
+ "user": {
105
+ "displayName": "Jaison A",
106
+ "userId": "07006398627763032071"
107
+ },
108
+ "user_tz": -330
109
+ },
110
+ "id": "iXrVxshWSK2Y",
111
+ "outputId": "be67027b-e257-43dc-c8b3-125d12de519a"
112
+ },
113
+ "outputs": [],
114
+ "source": [
115
+ "knn=KNeighborsClassifier(n_neighbors=15) #n_neighbors indicates no of clusters to be formed.\n",
116
+ "knn.fit(X_train,y_train) #training the knn model with training data.\n",
117
+ "\n",
118
+ "y_pred=knn.predict(X_test) #prediction using test data.\n",
119
+ "print(f\"Accuracy Score : {accuracy_score(y_test,y_pred)}\") #comparing original output with predicted output.\n",
120
+ "print(\"\\n\\nClassification Report : \\n\",classification_report(y_test,y_pred,zero_division=0)) #classification report."
121
+ ]
122
+ }
123
+ ],
124
+ "metadata": {
125
+ "colab": {
126
+ "authorship_tag": "ABX9TyOAjGoDOV/8NCJ7O3AdF9qL",
127
+ "provenance": []
128
+ },
129
+ "kernelspec": {
130
+ "display_name": "Python 3 (ipykernel)",
131
+ "language": "python",
132
+ "name": "python3"
133
+ },
134
+ "language_info": {
135
+ "codemirror_mode": {
136
+ "name": "ipython",
137
+ "version": 3
138
+ },
139
+ "file_extension": ".py",
140
+ "mimetype": "text/x-python",
141
+ "name": "python",
142
+ "nbconvert_exporter": "python",
143
+ "pygments_lexer": "ipython3",
144
+ "version": "3.12.4"
145
+ }
146
+ },
147
+ "nbformat": 4,
148
+ "nbformat_minor": 4
149
+ }