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,156 @@
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
+ "from sklearn import svm\n",
114
+ "import numpy as np\n",
115
+ "import matplotlib.pyplot as plt\n",
116
+ "\n",
117
+ "X, y = df.iloc[:, :2].values, df['class'].values\n",
118
+ "\n",
119
+ "clf = svm.SVC(kernel='linear').fit(X, y)\n",
120
+ "\n",
121
+ "x_min, x_max = X[:,0].min() - 1, X[:,0].max() + 1\n",
122
+ "y_min, y_max = X[:,1].min() - 1, X[:,1].max() + 1\n",
123
+ "xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02), np.arange(y_min, y_max, 0.02))\n",
124
+ "\n",
125
+ "Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]).reshape(xx.shape)\n",
126
+ "\n",
127
+ "plt.figure()\n",
128
+ "plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)\n",
129
+ "plt.scatter(X[:,0], X[:,1], c=y, cmap=plt.cm.coolwarm, s=20, edgecolors='k')\n",
130
+ "plt.title('Decision surface of linear SVC')\n",
131
+ "plt.show()"
132
+ ]
133
+ }
134
+ ],
135
+ "metadata": {
136
+ "kernelspec": {
137
+ "display_name": "Python 3 (ipykernel)",
138
+ "language": "python",
139
+ "name": "python3"
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.12.4"
152
+ }
153
+ },
154
+ "nbformat": 4,
155
+ "nbformat_minor": 5
156
+ }
@@ -0,0 +1,215 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "838f3d63-f48d-4003-8a20-767d87d5d63b",
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\n",
16
+ "from sklearn.model_selection import train_test_split\n",
17
+ "from sklearn.preprocessing import StandardScaler\n",
18
+ "from sklearn.decomposition import PCA\n",
19
+ "from sklearn.neighbors import KNeighborsClassifier\n",
20
+ "from sklearn import metrics\n",
21
+ "from mlxtend.plotting import plot_decision_regions\n",
22
+ "from scipy.cluster.hierarchy import dendrogram, linkage\n",
23
+ "from scipy.spatial import Voronoi, voronoi_plot_2d"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": null,
29
+ "id": "5a30696e-2e04-4ead-90c7-21dbd6b1d75d",
30
+ "metadata": {
31
+ "id": "10424106"
32
+ },
33
+ "outputs": [],
34
+ "source": [
35
+ "df = pd.read_csv(\"data/sobar-72.csv\")\n",
36
+ "display(df.head())\n",
37
+ "display(df.info())"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": null,
43
+ "id": "35e3b9f1-f5ed-4dd1-8a4d-aeb7fe77bea2",
44
+ "metadata": {
45
+ "id": "10424106"
46
+ },
47
+ "outputs": [],
48
+ "source": [
49
+ "cols = [\n",
50
+ " 'behavior_sexualRisk', 'intention_aggregation', 'attitude_consistency',\n",
51
+ " 'norm_significantPerson', 'perception_vulnerability', 'motivation_strength',\n",
52
+ " 'socialSupport_emotionality', 'empowerment_knowledge', 'ca_cervix'\n",
53
+ "]\n",
54
+ "sns.pairplot(df[cols], hue='ca_cervix')\n",
55
+ "plt.show()"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": null,
61
+ "id": "09bb4a6d-3807-44cb-b15e-2e6b3ff20d02",
62
+ "metadata": {
63
+ "id": "10424106"
64
+ },
65
+ "outputs": [],
66
+ "source": [
67
+ "X = df.drop(columns=['ca_cervix'])\n",
68
+ "y = df['ca_cervix']"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": null,
74
+ "id": "5a235b36-2136-4924-a6a3-834fde3e541c",
75
+ "metadata": {
76
+ "id": "10424106"
77
+ },
78
+ "outputs": [],
79
+ "source": [
80
+ "X_scaled = StandardScaler().fit_transform(X)\n",
81
+ "X_pca = PCA(n_components=2).fit_transform(X_scaled)\n",
82
+ "X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=0.4, random_state=4)"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": null,
88
+ "id": "7db3c778-fb6f-4509-8598-5df6928058e2",
89
+ "metadata": {
90
+ "id": "10424106"
91
+ },
92
+ "outputs": [],
93
+ "source": [
94
+ "similarities = ['euclidean', 'manhattan', 'minkowski']\n",
95
+ "for sim in similarities:\n",
96
+ " knn = KNeighborsClassifier(n_neighbors=5, metric=sim)\n",
97
+ " knn.fit(X_train, y_train)\n",
98
+ " y_pred = knn.predict(X_test)\n",
99
+ "\n",
100
+ " plot_decision_regions(X_train, np.array(y_train), clf=knn, legend=2)\n",
101
+ " plt.xlabel('X')\n",
102
+ " plt.ylabel('Y')\n",
103
+ " plt.title(f'KNN with K=5 using {sim.capitalize()} Distance')\n",
104
+ " plt.show()"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": null,
110
+ "id": "f4fee956-56f9-487d-b1fd-a2c32536fa0f",
111
+ "metadata": {
112
+ "id": "10424106"
113
+ },
114
+ "outputs": [],
115
+ "source": [
116
+ "k_values, accuracies = [], []\n",
117
+ "for k in range(1, 10):\n",
118
+ " knn = KNeighborsClassifier(n_neighbors=k)\n",
119
+ " knn.fit(X_train, y_train)\n",
120
+ " y_pred = knn.predict(X_test)\n",
121
+ " k_values.append(k)\n",
122
+ " accuracies.append(metrics.accuracy_score(y_test, y_pred))\n",
123
+ "\n",
124
+ "plt.figure(figsize=(4, 2))\n",
125
+ "plt.plot(k_values, accuracies, marker='o')\n",
126
+ "plt.title('K Value vs Accuracy')\n",
127
+ "plt.xlabel('K')\n",
128
+ "plt.ylabel('Accuracy')\n",
129
+ "plt.grid()\n",
130
+ "plt.show()"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "execution_count": null,
136
+ "id": "6ecc3e38-c791-48eb-ad01-a8149a2380ae",
137
+ "metadata": {
138
+ "id": "10424106"
139
+ },
140
+ "outputs": [],
141
+ "source": [
142
+ "plt.scatter(X_test[:, 0], X_test[:, 1], c=y_pred, cmap='coolwarm', edgecolors='k')\n",
143
+ "plt.title('Test Data Predictions')\n",
144
+ "plt.grid()\n",
145
+ "plt.show()"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": null,
151
+ "id": "9f40e9af-601f-4b4e-aadc-c3b27d4e4f11",
152
+ "metadata": {
153
+ "id": "10424106"
154
+ },
155
+ "outputs": [],
156
+ "source": [
157
+ "unique_labels = np.unique(y)\n",
158
+ "label_mapping = {label: i for i, label in enumerate(unique_labels)}\n",
159
+ "y_mapped = np.array([label_mapping[label] for label in y])\n",
160
+ "\n",
161
+ "linked = linkage(X_pca, method='single')\n",
162
+ "\n",
163
+ "plt.figure(figsize=(10, 7))\n",
164
+ "dendrogram(linked, orientation='top', distance_sort='descending', labels=y_mapped, show_leaf_counts=True)\n",
165
+ "plt.title('Dendrogram for KNN')\n",
166
+ "plt.xlabel('Data Points')\n",
167
+ "plt.ylabel('Distance')\n",
168
+ "plt.show()"
169
+ ]
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "execution_count": null,
174
+ "id": "5164b3a8-26f4-4855-a551-d5f9790b9975",
175
+ "metadata": {
176
+ "id": "10424106"
177
+ },
178
+ "outputs": [],
179
+ "source": [
180
+ "vor = Voronoi(X_pca)\n",
181
+ "fig = voronoi_plot_2d(vor, show_vertices=False, line_colors='black', line_width=2, line_alpha=0.6, point_size=10)\n",
182
+ "\n",
183
+ "plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, cmap='viridis', s=50, edgecolors='k')\n",
184
+ "plt.title('Voronoi Diagram with Target Variable')\n",
185
+ "plt.xlabel('X')\n",
186
+ "plt.ylabel('Y')\n",
187
+ "plt.show()"
188
+ ]
189
+ }
190
+ ],
191
+ "metadata": {
192
+ "colab": {
193
+ "provenance": []
194
+ },
195
+ "kernelspec": {
196
+ "display_name": "Python 3 (ipykernel)",
197
+ "language": "python",
198
+ "name": "python3"
199
+ },
200
+ "language_info": {
201
+ "codemirror_mode": {
202
+ "name": "ipython",
203
+ "version": 3
204
+ },
205
+ "file_extension": ".py",
206
+ "mimetype": "text/x-python",
207
+ "name": "python",
208
+ "nbconvert_exporter": "python",
209
+ "pygments_lexer": "ipython3",
210
+ "version": "3.12.4"
211
+ }
212
+ },
213
+ "nbformat": 4,
214
+ "nbformat_minor": 5
215
+ }
@@ -0,0 +1,78 @@
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
+ }
@@ -0,0 +1,114 @@
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
+ }
@@ -0,0 +1,115 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "2d42ca1a-531d-4d5b-aee4-a489d5033d1b",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import pandas as pd\n",
11
+ "import matplotlib.pyplot as plt\n",
12
+ "from sklearn.model_selection import train_test_split\n",
13
+ "from sklearn.linear_model import LinearRegression\n",
14
+ "from sklearn.metrics import r2_score"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "id": "f81220bc-5415-4b02-b2fd-fd5a8ff8c97a",
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "df = pd.read_csv('data/machine-data.csv')\n",
25
+ "print(\"Shape:\", df.shape)\n",
26
+ "df.head()"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": null,
32
+ "id": "958f3a04-3ae7-442b-a6e7-9134b9c5aeb3",
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "x = df.iloc[:,3:4].values\n",
37
+ "y = df.iloc[:,8].values\n",
38
+ "\n",
39
+ "X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)\n",
40
+ "regressor = LinearRegression()\n",
41
+ "regressor.fit(X_train, y_train)"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": null,
47
+ "id": "5b15fa5c-5c78-436b-8f33-4f431c797788",
48
+ "metadata": {},
49
+ "outputs": [],
50
+ "source": [
51
+ "y_pred = regressor.predict(X_test)\n",
52
+ "y_pred_train = regressor.predict(X_train)\n",
53
+ "print(\"Model Score: \", regressor.score(X_test, y_test))\n",
54
+ "print(\"R2 Score: \", r2_score(y_test, y_pred))"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": null,
60
+ "id": "b044ea95-014e-466b-b036-8ba9f96e3910",
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "plt.scatter(X_train, y_train, color = 'red')\n",
65
+ "plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n",
66
+ "plt.title('Y vs X (Training set)')\n",
67
+ "plt.xlabel('X')\n",
68
+ "plt.ylabel('Y')\n",
69
+ "plt.show()\n",
70
+ "plt.scatter(X_test, y_test, color = 'red')\n",
71
+ "plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n",
72
+ "plt.title('Y vs X (Test set)')\n",
73
+ "plt.xlabel('X')"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": null,
79
+ "id": "33c64414-d432-439e-a976-d28a9b4c3f2a",
80
+ "metadata": {},
81
+ "outputs": [],
82
+ "source": [
83
+ "X_future_expereince = [[2],[4]]\n",
84
+ "print(\"Prediction :\", regressor.predict(X_future_expereince))\n",
85
+ "plt.scatter(X_future_expereince, regressor.predict(X_future_expereince), color = 'red')\n",
86
+ "plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n",
87
+ "plt.title('Y vs X (Test set)')\n",
88
+ "plt.xlabel('X')\n",
89
+ "plt.ylabel('Y')\n",
90
+ "plt.show()"
91
+ ]
92
+ }
93
+ ],
94
+ "metadata": {
95
+ "kernelspec": {
96
+ "display_name": "Python 3 (ipykernel)",
97
+ "language": "python",
98
+ "name": "python3"
99
+ },
100
+ "language_info": {
101
+ "codemirror_mode": {
102
+ "name": "ipython",
103
+ "version": 3
104
+ },
105
+ "file_extension": ".py",
106
+ "mimetype": "text/x-python",
107
+ "name": "python",
108
+ "nbconvert_exporter": "python",
109
+ "pygments_lexer": "ipython3",
110
+ "version": "3.12.4"
111
+ }
112
+ },
113
+ "nbformat": 4,
114
+ "nbformat_minor": 5
115
+ }