noshot 11.0.0__py3-none-any.whl → 12.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 (74) hide show
  1. noshot/data/DLE FSD BDA/DLE/1. DNN (Image Classification).ipynb +389 -0
  2. noshot/data/DLE FSD BDA/DLE/2. DNN vs CNN.ipynb +516 -0
  3. noshot/data/DLE FSD BDA/DLE/3. CNN (Object Detecrion).ipynb +259 -0
  4. noshot/data/DLE FSD BDA/DLE/4. FCN (Image Segmentaion).ipynb +274 -0
  5. noshot/main.py +3 -3
  6. {noshot-11.0.0.dist-info → noshot-12.0.0.dist-info}/METADATA +1 -1
  7. noshot-12.0.0.dist-info/RECORD +13 -0
  8. noshot/data/ML TS XAI/ML/CNN(Image_for_Folders_5).ipynb +0 -201
  9. noshot/data/ML TS XAI/ML/CNN(Image_form_Folder_2).ipynb +0 -201
  10. noshot/data/ML TS XAI/ML/Json Codes/ML LAB CIA 2.ipynb +0 -409
  11. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Balance Scale Dataset).ipynb +0 -147
  12. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Rice Dataset).ipynb +0 -181
  13. noshot/data/ML TS XAI/ML/ML 1/10. HMM Veterbi.ipynb +0 -152
  14. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Balance Scale Dataset).ipynb +0 -117
  15. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Iris Dataset).ipynb +0 -156
  16. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Sobar-72 Dataset).ipynb +0 -215
  17. noshot/data/ML TS XAI/ML/ML 1/3. LDA (Balance Scale Dataset).ipynb +0 -78
  18. noshot/data/ML TS XAI/ML/ML 1/3. LDA (NPHA Doctor Visits Dataset).ipynb +0 -114
  19. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Machine Dataset).ipynb +0 -115
  20. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Real Estate Dataset).ipynb +0 -146
  21. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Magic04 Dataset).ipynb +0 -130
  22. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Wine Dataset).ipynb +0 -112
  23. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +0 -118
  24. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Wine Dataset).ipynb +0 -89
  25. noshot/data/ML TS XAI/ML/ML 1/7. SVM (Rice Dataset).ipynb +0 -120
  26. noshot/data/ML TS XAI/ML/ML 1/8. FeedForward NN (Sobar72 Dataset).ipynb +0 -262
  27. noshot/data/ML TS XAI/ML/ML 1/9. CNN (Cifar10 Dataset).ipynb +0 -156
  28. noshot/data/ML TS XAI/ML/ML 2/1. PCA.ipynb +0 -162
  29. noshot/data/ML TS XAI/ML/ML 2/10. CNN.ipynb +0 -100
  30. noshot/data/ML TS XAI/ML/ML 2/11. HMM.ipynb +0 -336
  31. noshot/data/ML TS XAI/ML/ML 2/2. KNN.ipynb +0 -149
  32. noshot/data/ML TS XAI/ML/ML 2/3. LDA.ipynb +0 -132
  33. noshot/data/ML TS XAI/ML/ML 2/4. Linear Regression.ipynb +0 -86
  34. noshot/data/ML TS XAI/ML/ML 2/5. Logistic Regression.ipynb +0 -115
  35. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Titanic).ipynb +0 -196
  36. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Wine).ipynb +0 -98
  37. noshot/data/ML TS XAI/ML/ML 2/7. SVM Linear.ipynb +0 -109
  38. noshot/data/ML TS XAI/ML/ML 2/8. SVM Non-Linear.ipynb +0 -195
  39. noshot/data/ML TS XAI/ML/ML 2/9. FNN With Regularization.ipynb +0 -189
  40. noshot/data/ML TS XAI/ML/ML 2/9. FNN Without Regularization.ipynb +0 -197
  41. noshot/data/ML TS XAI/ML/ML 2/All in One Lab CIA 1 Q.ipynb +0 -1087
  42. noshot/data/ML TS XAI/ML/ML 3 (Latest)/1. PCA EDA.ipynb +0 -274
  43. noshot/data/ML TS XAI/ML/ML 3 (Latest)/10. CNN.ipynb +0 -170
  44. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 2.ipynb +0 -1087
  45. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 3.ipynb +0 -178
  46. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 4.ipynb +0 -185
  47. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM.ipynb +0 -106
  48. noshot/data/ML TS XAI/ML/ML 3 (Latest)/2. KNN.ipynb +0 -177
  49. noshot/data/ML TS XAI/ML/ML 3 (Latest)/3. LDA.ipynb +0 -195
  50. noshot/data/ML TS XAI/ML/ML 3 (Latest)/4. Linear Regression.ipynb +0 -267
  51. noshot/data/ML TS XAI/ML/ML 3 (Latest)/5. Logistic Regression.ipynb +0 -104
  52. noshot/data/ML TS XAI/ML/ML 3 (Latest)/6. Bayesian Classifier.ipynb +0 -109
  53. noshot/data/ML TS XAI/ML/ML 3 (Latest)/7. SVM.ipynb +0 -220
  54. noshot/data/ML TS XAI/ML/ML 3 (Latest)/8. MLP.ipynb +0 -99
  55. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge - Lasso.ipynb +0 -211
  56. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge Lasso 2.ipynb +0 -99
  57. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Image Load Example.ipynb +0 -118
  58. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Updated_Untitled.ipynb +0 -603
  59. noshot/data/ML TS XAI/ML/ML Lab AllinOne.ipynb +0 -961
  60. noshot/data/ML TS XAI/ML/ML Lab H Sec/1. Iris Dataset (Softmax vs Sigmoid).ipynb +0 -231
  61. noshot/data/ML TS XAI/ML/ML Lab H Sec/2. Student Dataset (Overfit vs Regularized).ipynb +0 -269
  62. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Categorical (Overfit vs Regularized).ipynb +0 -274
  63. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Numerical (Overfit vs Regularized).ipynb +0 -263
  64. noshot/data/ML TS XAI/ML/ML Lab H Sec/4. Smart House System HMM.ipynb +0 -198
  65. noshot/data/ML TS XAI/ML/ML Lab H Sec/5. Fraud Detection System HMM.ipynb +0 -201
  66. noshot/data/ML TS XAI/ML/ML Lab H Sec/insurance.csv +0 -1339
  67. noshot/data/ML TS XAI/ML/ML Lab H Sec/iris1.data +0 -151
  68. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-mat.csv +0 -396
  69. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-por.csv +0 -650
  70. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +0 -691
  71. noshot-11.0.0.dist-info/RECORD +0 -72
  72. {noshot-11.0.0.dist-info → noshot-12.0.0.dist-info}/WHEEL +0 -0
  73. {noshot-11.0.0.dist-info → noshot-12.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  74. {noshot-11.0.0.dist-info → noshot-12.0.0.dist-info}/top_level.txt +0 -0
@@ -1,178 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "919144b8-e0cf-4047-8e7a-1ee69bc40be3",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import numpy as np\n",
11
- "import pandas as pd\n",
12
- "import networkx as nx\n",
13
- "import matplotlib.pyplot as plt\n",
14
- "from pprint import pprint\n",
15
- "\n",
16
- "states = ['O1', 'O2', 'O3']\n",
17
- "pi_obs = [0.25, 0.4, 0.35]\n",
18
- "\n",
19
- "state_space = pd.Series(pi_obs, index=states, name='states')\n",
20
- "print(state_space)\n",
21
- "print(\"Sum of initial state probabilities:\", state_space.sum())\n",
22
- "\n",
23
- "q_df = pd.DataFrame(columns=states, index=states)\n",
24
- "q_df.loc[states[0]] = [0.4, 0.2, 0.4]\n",
25
- "q_df.loc[states[1]] = [0.45, 0.45, 0.1]\n",
26
- "q_df.loc[states[2]] = [0.45, 0.25, 0.3]\n",
27
- "print(\"\\nTransition Matrix:\\n\", q_df)\n",
28
- "\n",
29
- "q = q_df.values\n",
30
- "print(\"\\nMatrix Values:\\n\", q, q.shape)\n",
31
- "print(\"\\nRow Sums (should be 1):\\n\", q_df.sum(axis=1))\n",
32
- "\n",
33
- "def _get_markov_edges(Q):\n",
34
- " edges = {}\n",
35
- " for col in Q.columns:\n",
36
- " for idx in Q.index:\n",
37
- " edges[(idx, col)] = Q.loc[idx, col]\n",
38
- " return edges\n",
39
- "\n",
40
- "edges_wts = _get_markov_edges(q_df)\n",
41
- "pprint(edges_wts)\n",
42
- "\n",
43
- "G = nx.MultiDiGraph()\n",
44
- "G.add_nodes_from(states)\n",
45
- "for (src, dst), weight in edges_wts.items():\n",
46
- " G.add_edge(src, dst, weight=weight, label=f\"{weight:.2f}\")\n",
47
- "\n",
48
- "pos = nx.spring_layout(G, seed=42)\n",
49
- "nx.draw_networkx(G, pos, with_labels=True, arrows=True)\n",
50
- "edge_labels = nx.get_edge_attributes(G, 'label')\n",
51
- "nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)\n",
52
- "plt.title(\"Observable States Transition Graph\")\n",
53
- "plt.show()\n",
54
- "\n",
55
- "hidden_states = ['S1', 'S2']\n",
56
- "pi = [0.5, 0.5]\n",
57
- "\n",
58
- "state_space = pd.Series(pi, index=hidden_states, name='states')\n",
59
- "print(\"\\nInitial Probabilities:\\n\", state_space)\n",
60
- "print(\"Sum:\", state_space.sum())\n",
61
- "\n",
62
- "a_df = pd.DataFrame(columns=hidden_states, index=hidden_states)\n",
63
- "a_df.loc[hidden_states[0]] = [0.7, 0.3]\n",
64
- "a_df.loc[hidden_states[1]] = [0.4, 0.6]\n",
65
- "print(\"\\nHidden Transition Matrix:\\n\", a_df)\n",
66
- "\n",
67
- "a = a_df.values\n",
68
- "print(\"\\nMatrix Values:\\n\", a)\n",
69
- "print(\"Shape:\", a.shape)\n",
70
- "print(\"Row Sums:\", a_df.sum(axis=1))\n",
71
- "\n",
72
- "observable_states = states\n",
73
- "b_df = pd.DataFrame(columns=observable_states, index=hidden_states)\n",
74
- "b_df.loc[hidden_states[0]] = [0.2, 0.6, 0.2]\n",
75
- "b_df.loc[hidden_states[1]] = [0.4, 0.1, 0.5]\n",
76
- "print(\"\\nEmission Matrix:\\n\", b_df)\n",
77
- "\n",
78
- "b = b_df.values\n",
79
- "print(\"\\nMatrix Values:\\n\", b)\n",
80
- "print(\"Shape:\", b.shape)\n",
81
- "print(\"Row Sums:\", b_df.sum(axis=1))\n",
82
- "\n",
83
- "hide_edges_wts = _get_markov_edges(a_df)\n",
84
- "emit_edges_wts = _get_markov_edges(b_df)\n",
85
- "\n",
86
- "pprint(hide_edges_wts)\n",
87
- "pprint(emit_edges_wts)\n",
88
- "\n",
89
- "G = nx.MultiDiGraph()\n",
90
- "G.add_nodes_from(hidden_states)\n",
91
- "for (src, dst), weight in hide_edges_wts.items():\n",
92
- " G.add_edge(src, dst, weight=weight, label=f\"{weight:.2f}\")\n",
93
- "\n",
94
- "pos = nx.spring_layout(G, seed=24)\n",
95
- "nx.draw_networkx(G, pos, with_labels=True, arrows=True)\n",
96
- "edge_labels = nx.get_edge_attributes(G, 'label')\n",
97
- "nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)\n",
98
- "plt.title(\"Hidden States Transition Graph\")\n",
99
- "plt.show()\n",
100
- "\n",
101
- "obs_seq = ['O2', 'O1', 'O3']\n",
102
- "obs_map = {state: idx for idx, state in enumerate(observable_states)}\n",
103
- "obs_idx_seq = [obs_map[obs] for obs in obs_seq]\n",
104
- "\n",
105
- "n_states = len(hidden_states)\n",
106
- "T = len(obs_seq)\n",
107
- "\n",
108
- "delta = np.zeros((T, n_states))\n",
109
- "psi = np.zeros((T, n_states), dtype=int)\n",
110
- "\n",
111
- "for i in range(n_states):\n",
112
- " delta[0, i] = pi[i] * b[i, obs_idx_seq[0]]\n",
113
- "\n",
114
- "for t in range(1, T):\n",
115
- " for j in range(n_states):\n",
116
- " max_prob = -1\n",
117
- " for i in range(n_states):\n",
118
- " prob = delta[t-1, i] * a[i, j] * b[j, obs_idx_seq[t]]\n",
119
- " if prob > max_prob:\n",
120
- " max_prob = prob\n",
121
- " psi[t, j] = i\n",
122
- " delta[t, j] = max_prob\n",
123
- "\n",
124
- "path = np.zeros(T, dtype=int)\n",
125
- "path[T-1] = np.argmax(delta[T-1])\n",
126
- "for t in range(T-2, -1, -1):\n",
127
- " path[t] = psi[t+1, path[t+1]]\n",
128
- "\n",
129
- "state_map = {0: 'S1', 1: 'S2'}\n",
130
- "state_path = [state_map[v] for v in path]\n",
131
- "\n",
132
- "result = pd.DataFrame({\n",
133
- " 'Observation': obs_seq,\n",
134
- " 'Best_Path': state_path\n",
135
- "})\n"
136
- ]
137
- },
138
- {
139
- "cell_type": "code",
140
- "execution_count": null,
141
- "id": "c5d97c8f-ad1b-4bf8-837d-d962f6a8c491",
142
- "metadata": {},
143
- "outputs": [],
144
- "source": [
145
- "result"
146
- ]
147
- },
148
- {
149
- "cell_type": "code",
150
- "execution_count": null,
151
- "id": "8d568585-7e84-4cf8-9015-ec7015dcaf57",
152
- "metadata": {},
153
- "outputs": [],
154
- "source": []
155
- }
156
- ],
157
- "metadata": {
158
- "kernelspec": {
159
- "display_name": "Python 3 (ipykernel)",
160
- "language": "python",
161
- "name": "python3"
162
- },
163
- "language_info": {
164
- "codemirror_mode": {
165
- "name": "ipython",
166
- "version": 3
167
- },
168
- "file_extension": ".py",
169
- "mimetype": "text/x-python",
170
- "name": "python",
171
- "nbconvert_exporter": "python",
172
- "pygments_lexer": "ipython3",
173
- "version": "3.12.4"
174
- }
175
- },
176
- "nbformat": 4,
177
- "nbformat_minor": 5
178
- }
@@ -1,185 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "63225994-29d4-429c-af2b-e6c3a1cebda9",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import numpy as np\n",
11
- "import pandas as pd\n",
12
- "import networkx.drawing.nx_pydot as gl\n",
13
- "import networkx as nx\n",
14
- "import matplotlib.pyplot as plt\n",
15
- "from pprint import pprint\n",
16
- "\n",
17
- "states = ['O1', 'O2', 'O3']\n",
18
- "pi_obs = [0.25, 0.4, 0.35]\n",
19
- "\n",
20
- "state_space = pd.Series(pi_obs, index=states, name='states')\n",
21
- "print(state_space)\n",
22
- "print(state_space.sum())\n",
23
- "\n",
24
- "q_df = pd.DataFrame(columns=states, index=states)\n",
25
- "q_df.loc[states[0]] = [0.4, 0.2, 0.4]\n",
26
- "q_df.loc[states[1]] = [0.45, 0.45, 0.1]\n",
27
- "q_df.loc[states[2]] = [0.45, 0.25, 0.3]\n",
28
- "print(q_df)\n",
29
- "\n",
30
- "q = q_df.values\n",
31
- "print(q, q.shape)\n",
32
- "print('\\n')\n",
33
- "print(q_df.sum(axis=1))\n",
34
- "\n",
35
- "def _get_markov_edges(Q):\n",
36
- " edges = {}\n",
37
- " for col in Q.columns:\n",
38
- " for idx in Q.index:\n",
39
- " edges[(idx, col)] = Q.loc[idx, col]\n",
40
- " return edges\n",
41
- "\n",
42
- "edges_wts = _get_markov_edges(q_df)\n",
43
- "pprint(edges_wts)\n",
44
- "\n",
45
- "G = nx.MultiDiGraph()\n",
46
- "G.add_nodes_from(states)\n",
47
- "print('Nodes:\\n')\n",
48
- "print(G.nodes())\n",
49
- "print('\\n')\n",
50
- "\n",
51
- "for k, v in edges_wts.items():\n",
52
- " tmp_origin, tmp_destination = k[0], k[1]\n",
53
- " G.add_edge(tmp_origin, tmp_destination, weight=v, label=v)\n",
54
- "\n",
55
- "print('Edges:')\n",
56
- "pprint(G.edges(data=True))\n",
57
- "\n",
58
- "pos = nx.drawing.nx_pydot.graphviz_layout(G, prog='dot')\n",
59
- "nx.draw_networkx(G, pos)\n",
60
- "plt.show()\n",
61
- "\n",
62
- "hidden_states = ['S1', 'S2']\n",
63
- "pi = [0.5, 0.5]\n",
64
- "print('\\n')\n",
65
- "state_space = pd.Series(pi, index=hidden_states, name='states')\n",
66
- "print(state_space)\n",
67
- "print('\\n')\n",
68
- "print(state_space.sum())\n",
69
- "\n",
70
- "a_df = pd.DataFrame(columns=hidden_states, index=hidden_states)\n",
71
- "a_df.loc[hidden_states[0]] = [0.7, 0.3]\n",
72
- "a_df.loc[hidden_states[1]] = [0.4, 0.6]\n",
73
- "print(a_df)\n",
74
- "\n",
75
- "a = a_df.values\n",
76
- "print('\\n')\n",
77
- "print(a)\n",
78
- "print(a.shape)\n",
79
- "print('\\n')\n",
80
- "print(a_df.sum(axis=1))\n",
81
- "\n",
82
- "observable_states = states\n",
83
- "b_df = pd.DataFrame(columns=observable_states, index=hidden_states)\n",
84
- "b_df.loc[hidden_states[0]] = [0.2, 0.6, 0.2]\n",
85
- "b_df.loc[hidden_states[1]] = [0.4, 0.1, 0.5]\n",
86
- "print(b_df)\n",
87
- "\n",
88
- "b = b_df.values\n",
89
- "print('\\n')\n",
90
- "print(b)\n",
91
- "print(b.shape)\n",
92
- "print('\\n')\n",
93
- "print(b_df.sum(axis=1))\n",
94
- "\n",
95
- "hide_edges_wts = _get_markov_edges(a_df)\n",
96
- "pprint(hide_edges_wts)\n",
97
- "\n",
98
- "emit_edges_wts = _get_markov_edges(b_df)\n",
99
- "pprint(emit_edges_wts)\n",
100
- "\n",
101
- "G = nx.MultiDiGraph()\n",
102
- "G.add_nodes_from(hidden_states)\n",
103
- "print('Nodes:\\n')\n",
104
- "print(G.nodes())\n",
105
- "print('\\n')\n",
106
- "\n",
107
- "for (origin, destination), weight in hide_edges_wts.items():\n",
108
- " G.add_edge(origin, destination, weight=weight, label=weight)\n",
109
- "\n",
110
- "pos = nx.drawing.nx_pydot.graphviz_layout(G, prog='neato')\n",
111
- "nx.draw_networkx(G, pos, with_labels=True, arrows=True)\n",
112
- "edge_labels = nx.get_edge_attributes(G, 'label')\n",
113
- "nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)\n",
114
- "plt.show()\n",
115
- "\n",
116
- "obs_seq = ['O2', 'O1', 'O3']\n",
117
- "\n",
118
- "obs_map = {state: idx for idx, state in enumerate(observable_states)}\n",
119
- "obs_idx_seq = [obs_map[obs] for obs in obs_seq]\n",
120
- "\n",
121
- "n_states = len(hidden_states)\n",
122
- "T = len(obs_seq)\n",
123
- "\n",
124
- "delta = np.zeros((T, n_states))\n",
125
- "psi = np.zeros((T, n_states), dtype=int)\n",
126
- "\n",
127
- "for i in range(n_states):\n",
128
- " delta[0, i] = pi[i] * b[i, obs_idx_seq[0]]\n",
129
- "\n",
130
- "for t in range(1, T):\n",
131
- " for j in range(n_states):\n",
132
- " max_prob = -1\n",
133
- " for i in range(n_states):\n",
134
- " prob = delta[t-1, i] * a[i, j] * b[j, obs_idx_seq[t]]\n",
135
- " if prob > max_prob:\n",
136
- " max_prob = prob\n",
137
- " psi[t, j] = i\n",
138
- " delta[t, j] = max_prob\n",
139
- "\n",
140
- "path = np.zeros(T, dtype=int)\n",
141
- "path[T-1] = np.argmax(delta[T-1])\n",
142
- "for t in range(T-2, -1, -1):\n",
143
- " path[t] = psi[t+1, path[t+1]]\n",
144
- "\n",
145
- "state_map = {0: 'S1', 1: 'S2'}\n",
146
- "state_path = [state_map[v] for v in path]\n",
147
- "\n",
148
- "result = pd.DataFrame({\n",
149
- " 'Observation': obs_seq,\n",
150
- " 'Best_Path': state_path\n",
151
- "})\n",
152
- "print(result)\n"
153
- ]
154
- },
155
- {
156
- "cell_type": "code",
157
- "execution_count": null,
158
- "id": "0eaf88b8-dac1-4441-8416-7fecffacdb37",
159
- "metadata": {},
160
- "outputs": [],
161
- "source": []
162
- }
163
- ],
164
- "metadata": {
165
- "kernelspec": {
166
- "display_name": "Python 3 (ipykernel)",
167
- "language": "python",
168
- "name": "python3"
169
- },
170
- "language_info": {
171
- "codemirror_mode": {
172
- "name": "ipython",
173
- "version": 3
174
- },
175
- "file_extension": ".py",
176
- "mimetype": "text/x-python",
177
- "name": "python",
178
- "nbconvert_exporter": "python",
179
- "pygments_lexer": "ipython3",
180
- "version": "3.12.4"
181
- }
182
- },
183
- "nbformat": 4,
184
- "nbformat_minor": 5
185
- }
@@ -1,106 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "46edf90f-3dee-4f88-965d-2502f38e2cf6",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "from hmmlearn import hmm\n",
11
- "import numpy as np\n",
12
- "\n",
13
- "# Observations\n",
14
- "observations = ['Walk', 'Shop', 'Clean']\n",
15
- "\n",
16
- "# Define model\n",
17
- "model = hmm.MultinomialHMM(n_components=2, n_trials=1, random_state=42)\n",
18
- "\n",
19
- "# Set start probabilities\n",
20
- "model.startprob_ = np.array([0.6, 0.4])\n",
21
- "\n",
22
- "# Set transition matrix\n",
23
- "model.transmat_ = np.array([\n",
24
- " [0.7, 0.3],\n",
25
- " \n",
26
- " [0.4, 0.6]\n",
27
- "])\n",
28
- "\n",
29
- "# Set emission probabilities\n",
30
- "model.emissionprob_ = np.array([\n",
31
- " [0.1, 0.4, 0.5], # State 0 (Rainy)\n",
32
- " [0.6, 0.3, 0.1], # State 1 (Sunny)\n",
33
- "])\n",
34
- "\n",
35
- "# Define observation sequence (ONE-HOT encoded now)\n",
36
- "obs_seq = np.array([\n",
37
- " [1, 0, 0], # Walk\n",
38
- " [0, 1, 0], # Shop\n",
39
- " [0, 0, 1] # Clean\n",
40
- "])\n",
41
- "\n",
42
- "# Predict hidden states\n",
43
- "logprob, hidden_states = model.decode(obs_seq, algorithm=\"viterbi\")\n",
44
- "\n",
45
- "# Output\n",
46
- "print(\"Observation sequence:\", [\"Walk\", \"Shop\", \"Clean\"])\n",
47
- "print(\"Predicted hidden states:\", hidden_states)\n"
48
- ]
49
- },
50
- {
51
- "cell_type": "code",
52
- "execution_count": null,
53
- "id": "c7dc7b6f-fb55-4f1d-82fc-cdd45c47a433",
54
- "metadata": {},
55
- "outputs": [],
56
- "source": [
57
- "import matplotlib.pyplot as plt\n",
58
- "\n",
59
- "# Observations\n",
60
- "observations = ['Walk', 'Shop', 'Clean']\n",
61
- "\n",
62
- "# (Assuming you already have hidden_states from model.decode)\n",
63
- "\n",
64
- "# Plotting\n",
65
- "plt.figure(figsize=(8, 3))\n",
66
- "plt.plot(hidden_states, marker='o', linestyle='-', color='b')\n",
67
- "plt.yticks([0, 1], ['Rainy', 'Sunny'])\n",
68
- "plt.xticks(range(len(observations)), observations)\n",
69
- "plt.xlabel('Observation')\n",
70
- "plt.ylabel('Hidden State')\n",
71
- "plt.title('Hidden States Prediction')\n",
72
- "plt.grid(True)\n",
73
- "plt.show()\n"
74
- ]
75
- },
76
- {
77
- "cell_type": "code",
78
- "execution_count": null,
79
- "id": "5dc1a86e-05d2-4482-b390-fc135fd9b81a",
80
- "metadata": {},
81
- "outputs": [],
82
- "source": []
83
- }
84
- ],
85
- "metadata": {
86
- "kernelspec": {
87
- "display_name": "Python 3 (ipykernel)",
88
- "language": "python",
89
- "name": "python3"
90
- },
91
- "language_info": {
92
- "codemirror_mode": {
93
- "name": "ipython",
94
- "version": 3
95
- },
96
- "file_extension": ".py",
97
- "mimetype": "text/x-python",
98
- "name": "python",
99
- "nbconvert_exporter": "python",
100
- "pygments_lexer": "ipython3",
101
- "version": "3.12.4"
102
- }
103
- },
104
- "nbformat": 4,
105
- "nbformat_minor": 5
106
- }
@@ -1,177 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "dbfcfea3",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import numpy as np\n",
11
- "import pandas as pd\n",
12
- "from sklearn.datasets import load_iris\n",
13
- "import matplotlib.pyplot as plt\n",
14
- "from sklearn.neighbors import KNeighborsClassifier\n",
15
- "from sklearn.datasets import make_classification\n",
16
- "from scipy.spatial import Voronoi, voronoi_plot_2d\n",
17
- "from sklearn.preprocessing import StandardScaler\n",
18
- "from sklearn.decomposition import PCA\n",
19
- "from sklearn.model_selection import train_test_split\n",
20
- "from sklearn.metrics import accuracy_score,classification_report\n",
21
- "from sklearn.cluster import KMeans\n"
22
- ]
23
- },
24
- {
25
- "cell_type": "code",
26
- "execution_count": null,
27
- "id": "a294fca6",
28
- "metadata": {},
29
- "outputs": [],
30
- "source": [
31
- "iris = load_iris()\n",
32
- "df = pd.DataFrame(data=iris.data, columns=iris.feature_names)\n",
33
- "df['target'] = iris.target\n",
34
- "\n",
35
- "X = np.array(df[iris.feature_names].iloc[:,:2])\n",
36
- "y = np.array(df['target'])\n",
37
- "\n",
38
- "y = np.array(df['target'])\n",
39
- "X = StandardScaler().fit_transform(X)\n",
40
- "pca = PCA(n_components=2)\n",
41
- "pct = pca.fit_transform(X)\n",
42
- "\n",
43
- "X = pct\n",
44
- "\n",
45
- "knn = KNeighborsClassifier(n_neighbors=3)\n",
46
- "knn.fit(X, y)\n",
47
- "\n",
48
- "x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n",
49
- "y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n",
50
- "xx, yy = np.meshgrid(np.linspace(x_min, x_max, 500), np.linspace(y_min, y_max, 500))\n",
51
- "grid_points = np.c_[xx.ravel(), yy.ravel()]\n",
52
- "\n",
53
- "Z = knn.predict(grid_points)\n",
54
- "Z = Z.reshape(xx.shape)\n",
55
- "\n",
56
- "plt.figure(figsize=(10, 7))\n",
57
- "plt.contourf(xx, yy, Z, alpha=0.3, cmap=plt.cm.Paired)\n",
58
- "plt.scatter(X[:, 0], X[:, 1], c=y, edgecolor='k', cmap=plt.cm.Paired, label='Data Points')\n",
59
- "\n",
60
- "vor = Voronoi(X)\n",
61
- "voronoi_plot_2d(vor, ax=plt.gca(), show_points=False, show_vertices=False, line_colors='black', line_width=0.8)\n",
62
- "\n",
63
- "plt.title(\"KNN Classification with Voronoi Diagram (k=3)\")\n",
64
- "plt.xlabel(\"Feature 1\")\n",
65
- "plt.ylabel(\"Feature 2\")\n",
66
- "plt.legend(loc=\"upper right\")\n",
67
- "plt.grid()\n",
68
- "plt.show()"
69
- ]
70
- },
71
- {
72
- "cell_type": "code",
73
- "execution_count": null,
74
- "id": "4b3a3076-7bd5-44e1-a0fb-1221821f6857",
75
- "metadata": {},
76
- "outputs": [],
77
- "source": [
78
- "df['target']"
79
- ]
80
- },
81
- {
82
- "cell_type": "code",
83
- "execution_count": null,
84
- "id": "c2bbe4ff",
85
- "metadata": {},
86
- "outputs": [],
87
- "source": [
88
- "import numpy as np\n",
89
- "import matplotlib.pyplot as plt\n",
90
- "from sklearn.datasets import load_iris\n",
91
- "from sklearn.neighbors import KNeighborsClassifier\n",
92
- "\n",
93
- "iris = load_iris()\n",
94
- "X = iris.data[:, :2]\n",
95
- "y = iris.target\n",
96
- "\n",
97
- "knn = KNeighborsClassifier(n_neighbors=5)\n",
98
- "knn.fit(X, y)\n",
99
- "\n",
100
- "x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n",
101
- "y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n",
102
- "xx, yy = np.meshgrid(np.linspace(x_min, x_max, 500), np.linspace(y_min, y_max, 500))\n",
103
- "\n",
104
- "Z = knn.predict(np.c_[xx.ravel(), yy.ravel()])\n",
105
- "Z = Z.reshape(xx.shape)\n",
106
- "\n",
107
- "plt.contourf(xx, yy, Z, alpha=0.8, cmap=plt.cm.RdYlBu)\n",
108
- "plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.brg, edgecolors='k')\n",
109
- "plt.xlabel(iris.feature_names[0])\n",
110
- "plt.ylabel(iris.feature_names[1])\n",
111
- "plt.title('KNN Decision Boundaries (k=5)')\n",
112
- "plt.show()"
113
- ]
114
- },
115
- {
116
- "cell_type": "code",
117
- "execution_count": null,
118
- "id": "65824231",
119
- "metadata": {},
120
- "outputs": [],
121
- "source": [
122
- "iris = load_iris()\n",
123
- "iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names)\n",
124
- "scaler = StandardScaler()\n",
125
- "scaled_features = scaler.fit_transform(iris_df)\n",
126
- "kmeans = KMeans(n_clusters=3, random_state=0,n_init=10) # Assuming 3 clusters (as in Iris dataset)\n",
127
- "clusters = kmeans.fit_predict(scaled_features)\n",
128
- "iris_df['cluster'] = clusters"
129
- ]
130
- },
131
- {
132
- "cell_type": "code",
133
- "execution_count": null,
134
- "id": "a2ba0f1c",
135
- "metadata": {},
136
- "outputs": [],
137
- "source": [
138
- "import matplotlib.pyplot as plt\n",
139
- "\n",
140
- "plt.scatter(iris_df['sepal length (cm)'], iris_df['sepal width (cm)'], c=iris_df['cluster'])\n",
141
- "plt.xlabel('Sepal Length (cm)')\n",
142
- "plt.ylabel('Sepal Width (cm)')\n",
143
- "plt.title('Unsupervised KNN (K-means) Clustering on Iris Dataset')\n",
144
- "plt.show()"
145
- ]
146
- },
147
- {
148
- "cell_type": "code",
149
- "execution_count": null,
150
- "id": "ed32cc12-bd6c-4677-8e01-19a45ae8338d",
151
- "metadata": {},
152
- "outputs": [],
153
- "source": []
154
- }
155
- ],
156
- "metadata": {
157
- "kernelspec": {
158
- "display_name": "Python 3 (ipykernel)",
159
- "language": "python",
160
- "name": "python3"
161
- },
162
- "language_info": {
163
- "codemirror_mode": {
164
- "name": "ipython",
165
- "version": 3
166
- },
167
- "file_extension": ".py",
168
- "mimetype": "text/x-python",
169
- "name": "python",
170
- "nbconvert_exporter": "python",
171
- "pygments_lexer": "ipython3",
172
- "version": "3.12.4"
173
- }
174
- },
175
- "nbformat": 4,
176
- "nbformat_minor": 5
177
- }