noshot 3.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.
Files changed (40) hide show
  1. noshot/data/ML TS XAI/XAI/Q1.ipynb +535 -0
  2. noshot/data/ML TS XAI/XAI/Q2.ipynb +38129 -0
  3. noshot/data/ML TS XAI/XAI/Q3.ipynb +1340 -0
  4. noshot/data/ML TS XAI/XAI/Q4.ipynb +246 -0
  5. noshot/data/ML TS XAI/XAI/Q5.ipynb +2450 -0
  6. {noshot-3.0.0.dist-info → noshot-5.0.0.dist-info}/METADATA +1 -1
  7. noshot-5.0.0.dist-info/RECORD +14 -0
  8. noshot/data/ML TS XAI/ML/Main/1. EDA-PCA (Balance Scale Dataset).ipynb +0 -139
  9. noshot/data/ML TS XAI/ML/Main/1. EDA-PCA (Rice Dataset).ipynb +0 -181
  10. noshot/data/ML TS XAI/ML/Main/10. HMM Veterbi.ipynb +0 -228
  11. noshot/data/ML TS XAI/ML/Main/2. KNN (Balance Scale Dataset).ipynb +0 -117
  12. noshot/data/ML TS XAI/ML/Main/2. KNN (Iris Dataset).ipynb +0 -165
  13. noshot/data/ML TS XAI/ML/Main/2. KNN (Sobar-72 Dataset).ipynb +0 -251
  14. noshot/data/ML TS XAI/ML/Main/3. LDA (Balance Scale Dataset).ipynb +0 -78
  15. noshot/data/ML TS XAI/ML/Main/3. LDA (NPHA Doctor Visits Dataset).ipynb +0 -114
  16. noshot/data/ML TS XAI/ML/Main/4. Linear Regression (Machine Dataset).ipynb +0 -115
  17. noshot/data/ML TS XAI/ML/Main/4. Linear Regression (Real Estate Dataset).ipynb +0 -159
  18. noshot/data/ML TS XAI/ML/Main/5. Logistic Regression (Magic04 Dataset).ipynb +0 -200
  19. noshot/data/ML TS XAI/ML/Main/5. Logistic Regression (Wine Dataset).ipynb +0 -112
  20. noshot/data/ML TS XAI/ML/Main/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +0 -153
  21. noshot/data/ML TS XAI/ML/Main/6. Naive Bayes Classifier (Wine Dataset).ipynb +0 -89
  22. noshot/data/ML TS XAI/ML/Main/7. SVM (Rice Dataset).ipynb +0 -208
  23. noshot/data/ML TS XAI/ML/Main/8. FeedForward NN (Sobar72 Dataset).ipynb +0 -260
  24. noshot/data/ML TS XAI/ML/Main/9. CNN (Cifar10 Dataset).ipynb +0 -238
  25. noshot/data/ML TS XAI/ML/Main/data/agaricus-lepiota.data +0 -8124
  26. noshot/data/ML TS XAI/ML/Main/data/balance-scale.txt +0 -625
  27. noshot/data/ML TS XAI/ML/Main/data/doctor-visits.csv +0 -715
  28. noshot/data/ML TS XAI/ML/Main/data/iris.csv +0 -151
  29. noshot/data/ML TS XAI/ML/Main/data/machine-data.csv +0 -210
  30. noshot/data/ML TS XAI/ML/Main/data/magic04.data +0 -19020
  31. noshot/data/ML TS XAI/ML/Main/data/real-estate.xlsx +0 -0
  32. noshot/data/ML TS XAI/ML/Main/data/rice.arff +0 -3826
  33. noshot/data/ML TS XAI/ML/Main/data/sobar-72.csv +0 -73
  34. noshot/data/ML TS XAI/ML/Main/data/wine-dataset.csv +0 -179
  35. noshot/data/ML TS XAI/ML/Other Codes.ipynb +0 -158
  36. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +0 -691
  37. noshot-3.0.0.dist-info/RECORD +0 -38
  38. {noshot-3.0.0.dist-info → noshot-5.0.0.dist-info}/WHEEL +0 -0
  39. {noshot-3.0.0.dist-info → noshot-5.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  40. {noshot-3.0.0.dist-info → noshot-5.0.0.dist-info}/top_level.txt +0 -0
@@ -1,165 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "f8872206-2c4c-4b9c-a146-4874bed47d58",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import numpy as np\n",
11
- "import pandas as pd\n",
12
- "import matplotlib.pyplot as plt\n",
13
- "import sklearn\n",
14
- "from sklearn import svm\n",
15
- "from sklearn.neighbors import KNeighborsClassifier\n",
16
- "from sklearn.model_selection import train_test_split\n",
17
- "from sklearn import metrics\n",
18
- "from sklearn.preprocessing import StandardScaler"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": null,
24
- "id": "6784e6b1-ab93-4529-85a0-8be414f00283",
25
- "metadata": {},
26
- "outputs": [],
27
- "source": [
28
- "df = pd.read_csv('data/iris.csv')\n",
29
- "df.head()"
30
- ]
31
- },
32
- {
33
- "cell_type": "code",
34
- "execution_count": null,
35
- "id": "7d9be320-b960-49d2-bf0b-d6193332b1f8",
36
- "metadata": {},
37
- "outputs": [],
38
- "source": [
39
- "class_mapper = {0: \"setosa\", 1: \"versicolor\", 2: \"virginica\"}\n",
40
- "df['target'] = df['class'].map(class_mapper)\n",
41
- "df.head()"
42
- ]
43
- },
44
- {
45
- "cell_type": "code",
46
- "execution_count": null,
47
- "id": "d523f9bd-14d5-42f6-80cc-fe8a8210fa1f",
48
- "metadata": {},
49
- "outputs": [],
50
- "source": [
51
- "feature = ['sepal length (cm)','sepal width (cm)','petal length (cm)','petal width (cm)']\n",
52
- "x = df.loc[:, feature]\n",
53
- "y = df.loc[:, 'target']"
54
- ]
55
- },
56
- {
57
- "cell_type": "code",
58
- "execution_count": null,
59
- "id": "f852a9d8-bb7a-49d3-a199-e47738c05a04",
60
- "metadata": {},
61
- "outputs": [],
62
- "source": [
63
- "x = StandardScaler().fit_transform(x)\n",
64
- "X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.4,\n",
65
- " random_state=4)\n",
66
- "print (X_train.shape)\n",
67
- "print (X_test.shape)\n",
68
- "knn = KNeighborsClassifier(n_neighbors=15)\n",
69
- "knn.fit(X_train, y_train) "
70
- ]
71
- },
72
- {
73
- "cell_type": "code",
74
- "execution_count": null,
75
- "id": "e57d7cdd-29b8-4235-aea7-9f904a70e9fd",
76
- "metadata": {},
77
- "outputs": [],
78
- "source": [
79
- "y_pred = knn.predict(np.array([5.2, 3.5, 1.1, 0.2]).reshape(1, -1))[0]\n",
80
- "print(\"Class Predicted [5.2, 3.5, 1.1, 0.2]:\", y_pred)"
81
- ]
82
- },
83
- {
84
- "cell_type": "code",
85
- "execution_count": null,
86
- "id": "b48aeb20-c569-4d0f-900c-82cd9ad92098",
87
- "metadata": {},
88
- "outputs": [],
89
- "source": [
90
- "y_pred = knn.predict(X_test)\n",
91
- "print(\"Accuracy:\", metrics.accuracy_score(y_test, y_pred))"
92
- ]
93
- },
94
- {
95
- "cell_type": "code",
96
- "execution_count": null,
97
- "id": "f72df1f8-5075-4d23-b93f-18a91e8fd1e0",
98
- "metadata": {},
99
- "outputs": [],
100
- "source": [
101
- "cm = metrics.confusion_matrix(y_test, knn.predict(X_test))\n",
102
- "metrics.ConfusionMatrixDisplay(cm, display_labels=['setosa','versicolor','virginica']).plot()\n",
103
- "plt.show()"
104
- ]
105
- },
106
- {
107
- "cell_type": "code",
108
- "execution_count": null,
109
- "id": "4c1df2d9-4e4b-43a1-aaec-d7eee15b716b",
110
- "metadata": {},
111
- "outputs": [],
112
- "source": [
113
- "X = df.iloc[:, :2].values\n",
114
- "y = df['class'].values\n",
115
- "\n",
116
- "def make_meshgrid(x, y, h=.02):\n",
117
- " x_min, x_max = x.min() - 1, x.max() + 1\n",
118
- " y_min, y_max = y.min() - 1, y.max() + 1\n",
119
- " xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))\n",
120
- " return xx, yy\n",
121
- "\n",
122
- "def plot_contours(ax, clf, xx, yy, **params):\n",
123
- " Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n",
124
- " Z = Z.reshape(xx.shape)\n",
125
- " out = ax.contourf(xx, yy, Z, **params)\n",
126
- " return out\n",
127
- "\n",
128
- "model = svm.SVC(kernel='linear')\n",
129
- "clf = model.fit(X, y)\n",
130
- "\n",
131
- "fig, ax = plt.subplots()\n",
132
- "title = ('Decision surface of linear SVC ')\n",
133
- "\n",
134
- "X0, X1 = X[:, 0], X[:, 1]\n",
135
- "xx, yy = make_meshgrid(X0, X1)\n",
136
- "\n",
137
- "plot_contours(ax, clf, xx, yy, cmap=plt.cm.coolwarm, alpha=0.8)\n",
138
- "ax.scatter(X0, X1, c=y, cmap=plt.cm.coolwarm, s=20, edgecolors='k')\n",
139
- "ax.set_title(title)\n",
140
- "plt.show()"
141
- ]
142
- }
143
- ],
144
- "metadata": {
145
- "kernelspec": {
146
- "display_name": "Python 3 (ipykernel)",
147
- "language": "python",
148
- "name": "python3"
149
- },
150
- "language_info": {
151
- "codemirror_mode": {
152
- "name": "ipython",
153
- "version": 3
154
- },
155
- "file_extension": ".py",
156
- "mimetype": "text/x-python",
157
- "name": "python",
158
- "nbconvert_exporter": "python",
159
- "pygments_lexer": "ipython3",
160
- "version": "3.12.4"
161
- }
162
- },
163
- "nbformat": 4,
164
- "nbformat_minor": 5
165
- }
@@ -1,251 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "10424106",
7
- "metadata": {
8
- "id": "10424106"
9
- },
10
- "outputs": [],
11
- "source": [
12
- "import numpy as np\n",
13
- "import pandas as pd\n",
14
- "import seaborn as sns\n",
15
- "import matplotlib.pyplot as plt"
16
- ]
17
- },
18
- {
19
- "cell_type": "code",
20
- "execution_count": null,
21
- "id": "0fc5ef2f",
22
- "metadata": {
23
- "id": "0fc5ef2f",
24
- "outputId": "a217f653-0c3c-42cd-c9c0-21b11c178506"
25
- },
26
- "outputs": [],
27
- "source": [
28
- "df=pd.read_csv(\"data/sobar-72.csv\")\n",
29
- "print(\"Shape:\", df.shape)\n",
30
- "df.head()"
31
- ]
32
- },
33
- {
34
- "cell_type": "code",
35
- "execution_count": null,
36
- "id": "4eec711d",
37
- "metadata": {
38
- "id": "4eec711d",
39
- "outputId": "a15e9bfc-b965-4e95-e7a4-0052839233f3"
40
- },
41
- "outputs": [],
42
- "source": [
43
- "df.columns"
44
- ]
45
- },
46
- {
47
- "cell_type": "code",
48
- "execution_count": null,
49
- "id": "4e39de4e",
50
- "metadata": {
51
- "id": "4e39de4e",
52
- "outputId": "348e3927-e93a-4b96-e78f-a2d022497da9"
53
- },
54
- "outputs": [],
55
- "source": [
56
- "df.info()"
57
- ]
58
- },
59
- {
60
- "cell_type": "code",
61
- "execution_count": null,
62
- "id": "7675bf00",
63
- "metadata": {
64
- "id": "7675bf00",
65
- "outputId": "3165d249-d062-4fa3-cf46-21452ad4aa42"
66
- },
67
- "outputs": [],
68
- "source": [
69
- "df.isnull().sum()"
70
- ]
71
- },
72
- {
73
- "cell_type": "code",
74
- "execution_count": null,
75
- "id": "1f10d8bd",
76
- "metadata": {
77
- "id": "1f10d8bd",
78
- "outputId": "e279942f-eb05-488a-84df-081f41c20a09"
79
- },
80
- "outputs": [],
81
- "source": [
82
- "cols = ['behavior_sexualRisk', 'intention_aggregation', 'attitude_consistency',\n",
83
- " 'norm_significantPerson', 'perception_vulnerability', 'motivation_strength',\n",
84
- " 'socialSupport_emotionality', 'empowerment_knowledge', 'ca_cervix']\n",
85
- "sns.pairplot(df[cols], hue='ca_cervix')"
86
- ]
87
- },
88
- {
89
- "cell_type": "code",
90
- "execution_count": null,
91
- "id": "3ae73b60-e7a5-4637-8c1d-94deb6ee1336",
92
- "metadata": {},
93
- "outputs": [],
94
- "source": [
95
- "X = df.drop(columns=['ca_cervix'])\n",
96
- "y = df['ca_cervix']"
97
- ]
98
- },
99
- {
100
- "cell_type": "code",
101
- "execution_count": null,
102
- "id": "e840e811",
103
- "metadata": {
104
- "id": "e840e811",
105
- "outputId": "21fe4718-db07-4188-bdce-10d7436eaa53"
106
- },
107
- "outputs": [],
108
- "source": [
109
- "import sklearn\n",
110
- "from sklearn import metrics\n",
111
- "from sklearn.neighbors import KNeighborsClassifier\n",
112
- "from sklearn.model_selection import train_test_split\n",
113
- "from sklearn.preprocessing import StandardScaler\n",
114
- "from sklearn.decomposition import PCA\n",
115
- "from mlxtend.plotting import plot_decision_regions\n",
116
- "\n",
117
- "x = StandardScaler().fit_transform(X)\n",
118
- "pca = PCA(n_components=2)\n",
119
- "x = pca.fit_transform(x)\n",
120
- "\n",
121
- "X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.4, random_state = 4)\n",
122
- "\n",
123
- "similarities=['euclidean','manhattan','minkowski']\n",
124
- "for sim in similarities:\n",
125
- " knn = KNeighborsClassifier(n_neighbors=5, metric=sim)\n",
126
- " knn.fit(X_train, y_train)\n",
127
- " y_pred = knn.predict(X_test)\n",
128
- " print(\"Accuracy:\", metrics.accuracy_score(y_test, y_pred))\n",
129
- " print(\"Distance Type:\", sim.capitalize())\n",
130
- " plot_decision_regions(X_train, np.array(y_train), clf=knn, legend=2)\n",
131
- " plt.xlabel('X')\n",
132
- " plt.ylabel('Y')\n",
133
- " plt.title('KNN with K=5 using '+str.capitalize(sim))\n",
134
- " plt.show()"
135
- ]
136
- },
137
- {
138
- "cell_type": "code",
139
- "execution_count": null,
140
- "id": "add0277c",
141
- "metadata": {
142
- "id": "add0277c",
143
- "outputId": "d82e7303-9d59-4f80-8d37-8f7cda39874a"
144
- },
145
- "outputs": [],
146
- "source": [
147
- "X, Y = [], []\n",
148
- "for i in range(1,10):\n",
149
- " knn = KNeighborsClassifier(n_neighbors = int(i))\n",
150
- " knn.fit(X_train, y_train)\n",
151
- " X.append(int(i))\n",
152
- " Y.append(metrics.accuracy_score(y_test, y_pred))\n",
153
- "\n",
154
- "plt.figure(figsize=(4,2))\n",
155
- "plt.plot(X, Y)\n",
156
- "plt.title('K Value vs Accuracy')\n",
157
- "plt.show()\n",
158
- "Y"
159
- ]
160
- },
161
- {
162
- "cell_type": "code",
163
- "execution_count": null,
164
- "id": "99411067",
165
- "metadata": {
166
- "id": "99411067",
167
- "outputId": "6f229212-5383-425f-c121-5cd27e6cd310"
168
- },
169
- "outputs": [],
170
- "source": [
171
- "plt.scatter(X_test[:,0], X_test[:,1], c=y_pred)\n",
172
- "plt.grid()\n",
173
- "plt.show()"
174
- ]
175
- },
176
- {
177
- "cell_type": "code",
178
- "execution_count": null,
179
- "id": "13bf2047",
180
- "metadata": {
181
- "id": "13bf2047",
182
- "outputId": "7f1a3184-c04e-44f8-a471-10d38e68e5ea"
183
- },
184
- "outputs": [],
185
- "source": [
186
- "from scipy.cluster.hierarchy import dendrogram, linkage\n",
187
- "\n",
188
- "unique_labels = np.unique(y)\n",
189
- "label_mapping = {label: i for i, label in enumerate(unique_labels)}\n",
190
- "new_y = np.array([label_mapping[label] for label in y])\n",
191
- "linked = linkage(x, 'single')\n",
192
- "\n",
193
- "plt.figure(figsize=(10, 7))\n",
194
- "dendrogram(linked,\n",
195
- " orientation='top',\n",
196
- " distance_sort='descending',\n",
197
- " labels=new_y,\n",
198
- " show_leaf_counts=True)\n",
199
- "plt.title('Dendrogram for KNN')\n",
200
- "plt.xlabel('Data Points')\n",
201
- "plt.ylabel('Distance')\n",
202
- "plt.show()"
203
- ]
204
- },
205
- {
206
- "cell_type": "code",
207
- "execution_count": null,
208
- "id": "ff0ac60f",
209
- "metadata": {
210
- "id": "ff0ac60f",
211
- "outputId": "31b575f3-f8e7-42ff-d01f-69f86e7d9fd0"
212
- },
213
- "outputs": [],
214
- "source": [
215
- "from scipy.spatial import Voronoi, voronoi_plot_2d\n",
216
- "\n",
217
- "vor = Voronoi(x)\n",
218
- "fig = voronoi_plot_2d(vor, show_vertices=False, line_colors='black', line_width=2, line_alpha=0.6, point_size=10)\n",
219
- "plt.scatter(x[:, 0], x[:, 1], c=y, cmap='viridis', s=50, edgecolors='black') # Color points by target variable\n",
220
- "plt.title('Voronoi Diagram with Target Variable')\n",
221
- "plt.xlabel('X')\n",
222
- "plt.ylabel('Y')\n",
223
- "plt.show()"
224
- ]
225
- }
226
- ],
227
- "metadata": {
228
- "colab": {
229
- "provenance": []
230
- },
231
- "kernelspec": {
232
- "display_name": "Python 3 (ipykernel)",
233
- "language": "python",
234
- "name": "python3"
235
- },
236
- "language_info": {
237
- "codemirror_mode": {
238
- "name": "ipython",
239
- "version": 3
240
- },
241
- "file_extension": ".py",
242
- "mimetype": "text/x-python",
243
- "name": "python",
244
- "nbconvert_exporter": "python",
245
- "pygments_lexer": "ipython3",
246
- "version": "3.12.4"
247
- }
248
- },
249
- "nbformat": 4,
250
- "nbformat_minor": 5
251
- }
@@ -1,78 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "96ac04a5-6577-4da4-8454-3b10535351f8",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import pandas as pd\n",
11
- "import matplotlib.pyplot as plt\n",
12
- "from sklearn.preprocessing import StandardScaler\n",
13
- "from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA"
14
- ]
15
- },
16
- {
17
- "cell_type": "code",
18
- "execution_count": null,
19
- "id": "b1ffa4dc-488f-4238-877b-5cbd6fb48e4e",
20
- "metadata": {},
21
- "outputs": [],
22
- "source": [
23
- "cols = ['class name','left-weight','left-distance','right-weight','right-distance']\n",
24
- "df = pd.read_table('data/balance-scale.txt', delimiter = \",\", names=cols)\n",
25
- "print(\"Shape:\", df.shape)\n",
26
- "df.head()"
27
- ]
28
- },
29
- {
30
- "cell_type": "code",
31
- "execution_count": null,
32
- "id": "069bba36-4187-48e4-bc5b-d1443c1ee87c",
33
- "metadata": {},
34
- "outputs": [],
35
- "source": [
36
- "features = ['left-weight','left-distance','right-weight','right-distance']\n",
37
- "x = df.loc[:,features]\n",
38
- "y = df.loc[:,'class name']\n",
39
- "lda = LDA(n_components=2)\n",
40
- "lda_X = lda.fit(x,y).transform(x)"
41
- ]
42
- },
43
- {
44
- "cell_type": "code",
45
- "execution_count": null,
46
- "id": "66c2b6ac-6163-4f36-ae6b-3a9e32e578ce",
47
- "metadata": {},
48
- "outputs": [],
49
- "source": [
50
- "plt.scatter(lda_X[y == 'L', 0], lda_X[y == 'L', 1], s=50, c='orange', label='L')\n",
51
- "plt.scatter(lda_X[y == 'B', 0], lda_X[y == 'B', 1], s=50, c='blue', label='B')\n",
52
- "plt.scatter(lda_X[y == 'R', 0], lda_X[y == 'R', 1], s=50, c='green', label='R')\n",
53
- "plt.title('LDA plot for cmc DataSet')"
54
- ]
55
- }
56
- ],
57
- "metadata": {
58
- "kernelspec": {
59
- "display_name": "Python 3 (ipykernel)",
60
- "language": "python",
61
- "name": "python3"
62
- },
63
- "language_info": {
64
- "codemirror_mode": {
65
- "name": "ipython",
66
- "version": 3
67
- },
68
- "file_extension": ".py",
69
- "mimetype": "text/x-python",
70
- "name": "python",
71
- "nbconvert_exporter": "python",
72
- "pygments_lexer": "ipython3",
73
- "version": "3.12.4"
74
- }
75
- },
76
- "nbformat": 4,
77
- "nbformat_minor": 5
78
- }
@@ -1,114 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "68f40eda",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "import pandas as pd\n",
11
- "import numpy as np\n",
12
- "import matplotlib.pyplot as plt"
13
- ]
14
- },
15
- {
16
- "cell_type": "code",
17
- "execution_count": null,
18
- "id": "066999b2",
19
- "metadata": {},
20
- "outputs": [],
21
- "source": [
22
- "df = pd.read_csv(r\"data\\doctor-visits.csv\")\n",
23
- "print(\"Shape:\", df.shape)\n",
24
- "df.head()"
25
- ]
26
- },
27
- {
28
- "cell_type": "code",
29
- "execution_count": null,
30
- "id": "839d6a31",
31
- "metadata": {},
32
- "outputs": [],
33
- "source": [
34
- "df.columns"
35
- ]
36
- },
37
- {
38
- "cell_type": "code",
39
- "execution_count": null,
40
- "id": "7d105e4c",
41
- "metadata": {},
42
- "outputs": [],
43
- "source": [
44
- "X = df.drop(columns=['Number of Doctors Visited'])\n",
45
- "Y = df['Number of Doctors Visited']"
46
- ]
47
- },
48
- {
49
- "cell_type": "code",
50
- "execution_count": null,
51
- "id": "05dc3f49-79f4-4862-91e8-89aab4ae2b2f",
52
- "metadata": {},
53
- "outputs": [],
54
- "source": [
55
- "from sklearn import metrics\n",
56
- "from sklearn.discriminant_analysis import LinearDiscriminantAnalysis\n",
57
- "from sklearn.model_selection import train_test_split\n",
58
- "\n",
59
- "X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.4, random_state=4)\n",
60
- "\n",
61
- "lda = LinearDiscriminantAnalysis(n_components=2)\n",
62
- "X_train = lda.fit_transform(X_train, y_train)\n",
63
- "X_test = lda.fit_transform(X_test,y_test)"
64
- ]
65
- },
66
- {
67
- "cell_type": "code",
68
- "execution_count": null,
69
- "id": "9e25c024-8dd8-40da-b755-1ed36dfc197c",
70
- "metadata": {},
71
- "outputs": [],
72
- "source": [
73
- "lda.fit(X_train,y_train)\n",
74
- "y_pred=lda.predict(X_test)\n",
75
- "print (\"Accuracy:\",metrics.accuracy_score(y_test, y_pred))"
76
- ]
77
- },
78
- {
79
- "cell_type": "code",
80
- "execution_count": null,
81
- "id": "7f0537a8-6820-4859-a3f5-f24096dfa66b",
82
- "metadata": {},
83
- "outputs": [],
84
- "source": [
85
- "plt.scatter(X_train[:, 0], X_train[:, 1], c=y_train, cmap='viridis')\n",
86
- "plt.title('LDA Dimensionality Reduction')\n",
87
- "plt.xlabel('LDA Component 1')\n",
88
- "plt.ylabel('LDA Component 2')\n",
89
- "plt.show()"
90
- ]
91
- }
92
- ],
93
- "metadata": {
94
- "kernelspec": {
95
- "display_name": "Python 3 (ipykernel)",
96
- "language": "python",
97
- "name": "python3"
98
- },
99
- "language_info": {
100
- "codemirror_mode": {
101
- "name": "ipython",
102
- "version": 3
103
- },
104
- "file_extension": ".py",
105
- "mimetype": "text/x-python",
106
- "name": "python",
107
- "nbconvert_exporter": "python",
108
- "pygments_lexer": "ipython3",
109
- "version": "3.12.4"
110
- }
111
- },
112
- "nbformat": 4,
113
- "nbformat_minor": 5
114
- }