noshot 11.0.0__py3-none-any.whl → 13.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 (93) hide show
  1. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/1. DNN (Image Classification).ipynb +389 -0
  2. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/2. DNN vs CNN.ipynb +516 -0
  3. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/3. CNN (Object Detecrion).ipynb +259 -0
  4. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/4. FCN (Image Segmentaion).ipynb +274 -0
  5. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.1 DNN (Pytorch).ipynb +164 -0
  6. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.2 DNN (Tensorflow).ipynb +94 -0
  7. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.3 DNN (Image Classification).ipynb +134 -0
  8. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.1 DNN vs CNN.ipynb +127 -0
  9. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.2 DNN vs CNN.ipynb +123 -0
  10. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/4. FCNN (Image Segmentation).ipynb +108 -0
  11. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Lab Excercise (Training DNN).ipynb +646 -0
  12. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Load-Images.ipynb +553 -0
  13. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex1.ipynb +216 -0
  14. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex2.ipynb +195 -0
  15. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex3.ipynb +427 -0
  16. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex4.ipynb +186 -0
  17. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/DNN Ex No 1.ipynb +398 -0
  18. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Ex No 1 Build in dataset.ipynb +171 -0
  19. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Exp1-Short-DL_ANN_ImageClassification.ipynb +401 -0
  20. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/OR GATE .ipynb +8511 -0
  21. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp02/Exp2-Short-DL_CNN_ImageClassification.ipynb +737 -0
  22. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp03/DL-Ex3-RNN.ipynb +591 -0
  23. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp04/Ex no 4.ipynb +551 -0
  24. noshot/main.py +3 -3
  25. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/METADATA +1 -1
  26. noshot-13.0.0.dist-info/RECORD +32 -0
  27. noshot/data/ML TS XAI/ML/CNN(Image_for_Folders_5).ipynb +0 -201
  28. noshot/data/ML TS XAI/ML/CNN(Image_form_Folder_2).ipynb +0 -201
  29. noshot/data/ML TS XAI/ML/Json Codes/ML LAB CIA 2.ipynb +0 -409
  30. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Balance Scale Dataset).ipynb +0 -147
  31. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Rice Dataset).ipynb +0 -181
  32. noshot/data/ML TS XAI/ML/ML 1/10. HMM Veterbi.ipynb +0 -152
  33. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Balance Scale Dataset).ipynb +0 -117
  34. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Iris Dataset).ipynb +0 -156
  35. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Sobar-72 Dataset).ipynb +0 -215
  36. noshot/data/ML TS XAI/ML/ML 1/3. LDA (Balance Scale Dataset).ipynb +0 -78
  37. noshot/data/ML TS XAI/ML/ML 1/3. LDA (NPHA Doctor Visits Dataset).ipynb +0 -114
  38. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Machine Dataset).ipynb +0 -115
  39. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Real Estate Dataset).ipynb +0 -146
  40. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Magic04 Dataset).ipynb +0 -130
  41. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Wine Dataset).ipynb +0 -112
  42. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +0 -118
  43. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Wine Dataset).ipynb +0 -89
  44. noshot/data/ML TS XAI/ML/ML 1/7. SVM (Rice Dataset).ipynb +0 -120
  45. noshot/data/ML TS XAI/ML/ML 1/8. FeedForward NN (Sobar72 Dataset).ipynb +0 -262
  46. noshot/data/ML TS XAI/ML/ML 1/9. CNN (Cifar10 Dataset).ipynb +0 -156
  47. noshot/data/ML TS XAI/ML/ML 2/1. PCA.ipynb +0 -162
  48. noshot/data/ML TS XAI/ML/ML 2/10. CNN.ipynb +0 -100
  49. noshot/data/ML TS XAI/ML/ML 2/11. HMM.ipynb +0 -336
  50. noshot/data/ML TS XAI/ML/ML 2/2. KNN.ipynb +0 -149
  51. noshot/data/ML TS XAI/ML/ML 2/3. LDA.ipynb +0 -132
  52. noshot/data/ML TS XAI/ML/ML 2/4. Linear Regression.ipynb +0 -86
  53. noshot/data/ML TS XAI/ML/ML 2/5. Logistic Regression.ipynb +0 -115
  54. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Titanic).ipynb +0 -196
  55. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Wine).ipynb +0 -98
  56. noshot/data/ML TS XAI/ML/ML 2/7. SVM Linear.ipynb +0 -109
  57. noshot/data/ML TS XAI/ML/ML 2/8. SVM Non-Linear.ipynb +0 -195
  58. noshot/data/ML TS XAI/ML/ML 2/9. FNN With Regularization.ipynb +0 -189
  59. noshot/data/ML TS XAI/ML/ML 2/9. FNN Without Regularization.ipynb +0 -197
  60. noshot/data/ML TS XAI/ML/ML 2/All in One Lab CIA 1 Q.ipynb +0 -1087
  61. noshot/data/ML TS XAI/ML/ML 3 (Latest)/1. PCA EDA.ipynb +0 -274
  62. noshot/data/ML TS XAI/ML/ML 3 (Latest)/10. CNN.ipynb +0 -170
  63. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 2.ipynb +0 -1087
  64. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 3.ipynb +0 -178
  65. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 4.ipynb +0 -185
  66. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM.ipynb +0 -106
  67. noshot/data/ML TS XAI/ML/ML 3 (Latest)/2. KNN.ipynb +0 -177
  68. noshot/data/ML TS XAI/ML/ML 3 (Latest)/3. LDA.ipynb +0 -195
  69. noshot/data/ML TS XAI/ML/ML 3 (Latest)/4. Linear Regression.ipynb +0 -267
  70. noshot/data/ML TS XAI/ML/ML 3 (Latest)/5. Logistic Regression.ipynb +0 -104
  71. noshot/data/ML TS XAI/ML/ML 3 (Latest)/6. Bayesian Classifier.ipynb +0 -109
  72. noshot/data/ML TS XAI/ML/ML 3 (Latest)/7. SVM.ipynb +0 -220
  73. noshot/data/ML TS XAI/ML/ML 3 (Latest)/8. MLP.ipynb +0 -99
  74. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge - Lasso.ipynb +0 -211
  75. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge Lasso 2.ipynb +0 -99
  76. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Image Load Example.ipynb +0 -118
  77. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Updated_Untitled.ipynb +0 -603
  78. noshot/data/ML TS XAI/ML/ML Lab AllinOne.ipynb +0 -961
  79. noshot/data/ML TS XAI/ML/ML Lab H Sec/1. Iris Dataset (Softmax vs Sigmoid).ipynb +0 -231
  80. noshot/data/ML TS XAI/ML/ML Lab H Sec/2. Student Dataset (Overfit vs Regularized).ipynb +0 -269
  81. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Categorical (Overfit vs Regularized).ipynb +0 -274
  82. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Numerical (Overfit vs Regularized).ipynb +0 -263
  83. noshot/data/ML TS XAI/ML/ML Lab H Sec/4. Smart House System HMM.ipynb +0 -198
  84. noshot/data/ML TS XAI/ML/ML Lab H Sec/5. Fraud Detection System HMM.ipynb +0 -201
  85. noshot/data/ML TS XAI/ML/ML Lab H Sec/insurance.csv +0 -1339
  86. noshot/data/ML TS XAI/ML/ML Lab H Sec/iris1.data +0 -151
  87. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-mat.csv +0 -396
  88. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-por.csv +0 -650
  89. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +0 -691
  90. noshot-11.0.0.dist-info/RECORD +0 -72
  91. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/WHEEL +0 -0
  92. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  93. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/top_level.txt +0 -0
@@ -1,195 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {
6
- "id": "4HHtR8-qzyql"
7
- },
8
- "source": [
9
- "### **Iris Data**"
10
- ]
11
- },
12
- {
13
- "cell_type": "code",
14
- "execution_count": null,
15
- "metadata": {
16
- "colab": {
17
- "base_uri": "https://localhost:8080/",
18
- "height": 680
19
- },
20
- "executionInfo": {
21
- "elapsed": 2075,
22
- "status": "ok",
23
- "timestamp": 1742277187382,
24
- "user": {
25
- "displayName": "Jaison A",
26
- "userId": "07006398627763032071"
27
- },
28
- "user_tz": -330
29
- },
30
- "id": "RNGrFpf-z7_7",
31
- "outputId": "5d8ff477-fbee-40cf-9746-4ef35b48397e"
32
- },
33
- "outputs": [],
34
- "source": [
35
- "import numpy as np\n",
36
- "import matplotlib.pyplot as plt\n",
37
- "from sklearn.datasets import load_iris\n",
38
- "from sklearn.model_selection import train_test_split\n",
39
- "from sklearn.preprocessing import StandardScaler\n",
40
- "from sklearn.svm import SVC\n",
41
- "from sklearn.decomposition import PCA\n",
42
- "from sklearn.metrics import classification_report, accuracy_score,ConfusionMatrixDisplay\n",
43
- "\n",
44
- "iris = load_iris()\n",
45
- "X = iris.data\n",
46
- "y = iris.target\n",
47
- "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
48
- "scaler = StandardScaler()\n",
49
- "X_train = scaler.fit_transform(X_train)\n",
50
- "X_test = scaler.transform(X_test)\n",
51
- "\n",
52
- "# Reduce to 2D using PCA\n",
53
- "pca = PCA(n_components=2)\n",
54
- "X_train_2d = pca.fit_transform(X_train)\n",
55
- "X_test_2d = pca.transform(X_test)\n",
56
- "\n",
57
- "# Train SVM on 2D data\n",
58
- "svm_model = SVC(kernel='rbf')\n",
59
- "svm_model.fit(X_train_2d, y_train)\n",
60
- "y_pred = svm_model.predict(X_test_2d)\n",
61
- "print(\"Classification Report:\")\n",
62
- "print(classification_report(y_test, y_pred))\n",
63
- "print(\"Accuracy Score:\", accuracy_score(y_test, y_pred))\n",
64
- "\n",
65
- "# Plot decision boundary\n",
66
- "def plot_decision_boundary(X, y, model):\n",
67
- " x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n",
68
- " y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n",
69
- " xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.01), np.arange(y_min, y_max, 0.01))\n",
70
- " Z = model.predict(np.c_[xx.ravel(), yy.ravel()])\n",
71
- " Z = Z.reshape(xx.shape)\n",
72
- " plt.contourf(xx, yy, Z, alpha=0.8, cmap=plt.cm.coolwarm)\n",
73
- " plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', marker='o', cmap=plt.cm.coolwarm)\n",
74
- " plt.xlabel('PCA Component 1')\n",
75
- " plt.ylabel('PCA Component 2')\n",
76
- " plt.title('SVM Decision Boundary (2D)')\n",
77
- " plt.show()\n",
78
- "\n",
79
- "plot_decision_boundary(X_train_2d, y_train, svm_model)"
80
- ]
81
- },
82
- {
83
- "cell_type": "markdown",
84
- "metadata": {
85
- "id": "x6eBRP8vztnF"
86
- },
87
- "source": [
88
- "### **Heart Data**"
89
- ]
90
- },
91
- {
92
- "cell_type": "code",
93
- "execution_count": null,
94
- "metadata": {
95
- "colab": {
96
- "base_uri": "https://localhost:8080/",
97
- "height": 1000
98
- },
99
- "executionInfo": {
100
- "elapsed": 49651,
101
- "status": "ok",
102
- "timestamp": 1743412125091,
103
- "user": {
104
- "displayName": "Jaison A",
105
- "userId": "07006398627763032071"
106
- },
107
- "user_tz": -330
108
- },
109
- "id": "7pI03vdRzYV0",
110
- "outputId": "14feb814-e167-4351-a662-bb1d044531f8"
111
- },
112
- "outputs": [],
113
- "source": [
114
- "import pandas as pd\n",
115
- "import numpy as np\n",
116
- "import matplotlib.pyplot as plt\n",
117
- "from sklearn.model_selection import train_test_split\n",
118
- "from sklearn.preprocessing import StandardScaler\n",
119
- "from sklearn.svm import SVC\n",
120
- "from sklearn.decomposition import PCA\n",
121
- "from sklearn.metrics import classification_report, accuracy_score,ConfusionMatrixDisplay,confusion_matrix\n",
122
- "\n",
123
- "df = pd.read_csv('/content/heart_disease_uci.csv')\n",
124
- "for col in df.columns:\n",
125
- " if df[col].dtype == 'object':\n",
126
- " df[col].fillna(df[col].mode()[0], inplace=True)\n",
127
- " else:\n",
128
- " df[col].fillna(df[col].mean(), inplace=True)\n",
129
- "df = pd.get_dummies(df, drop_first=True)\n",
130
- "X = df.drop('num', axis=1)\n",
131
- "y = df['num']\n",
132
- "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
133
- "scaler = StandardScaler()\n",
134
- "X_train = scaler.fit_transform(X_train)\n",
135
- "X_test = scaler.transform(X_test)\n",
136
- "\n",
137
- "# Reduce to 2D using PCA\n",
138
- "pca = PCA(n_components=2)\n",
139
- "X_train_2d = pca.fit_transform(X_train)\n",
140
- "X_test_2d = pca.transform(X_test)\n",
141
- "\n",
142
- "# Train SVM on 2D data\n",
143
- "svm_model = SVC(kernel='rbf')\n",
144
- "svm_model.fit(X_train_2d, y_train)\n",
145
- "y_pred = svm_model.predict(X_test_2d)\n",
146
- "print(\"Classification Report:\")\n",
147
- "print(classification_report(y_test, y_pred))\n",
148
- "print(\"Accuracy Score:\", accuracy_score(y_test, y_pred))\n",
149
- "ConfusionMatrixDisplay(confusion_matrix(y_test, y_pred)).plot()\n",
150
- "plt.show()\n",
151
- "\n",
152
- "# Plot decision boundary\n",
153
- "def plot_decision_boundary(X, y, model):\n",
154
- " x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n",
155
- " y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n",
156
- " xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.01), np.arange(y_min, y_max, 0.01))\n",
157
- " Z = model.predict(np.c_[xx.ravel(), yy.ravel()])\n",
158
- " Z = Z.reshape(xx.shape)\n",
159
- " plt.contourf(xx, yy, Z, alpha=0.8, cmap=plt.cm.coolwarm)\n",
160
- " plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='k', marker='o', cmap=plt.cm.coolwarm)\n",
161
- " plt.xlabel('PCA Component 1')\n",
162
- " plt.ylabel('PCA Component 2')\n",
163
- " plt.title('SVM Decision Boundary (2D)')\n",
164
- " plt.show()\n",
165
- "\n",
166
- "plot_decision_boundary(X_train_2d, y_train, svm_model)"
167
- ]
168
- }
169
- ],
170
- "metadata": {
171
- "colab": {
172
- "authorship_tag": "ABX9TyMpHE13jXi9Fv5ZNpyOjg3b",
173
- "provenance": []
174
- },
175
- "kernelspec": {
176
- "display_name": "Python 3 (ipykernel)",
177
- "language": "python",
178
- "name": "python3"
179
- },
180
- "language_info": {
181
- "codemirror_mode": {
182
- "name": "ipython",
183
- "version": 3
184
- },
185
- "file_extension": ".py",
186
- "mimetype": "text/x-python",
187
- "name": "python",
188
- "nbconvert_exporter": "python",
189
- "pygments_lexer": "ipython3",
190
- "version": "3.12.4"
191
- }
192
- },
193
- "nbformat": 4,
194
- "nbformat_minor": 4
195
- }
@@ -1,189 +0,0 @@
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": 45818,
13
- "status": "ok",
14
- "timestamp": 1743487279036,
15
- "user": {
16
- "displayName": "Jaison A",
17
- "userId": "07006398627763032071"
18
- },
19
- "user_tz": -330
20
- },
21
- "id": "TNO6tqQ977Mr",
22
- "outputId": "67fbc432-5c26-4e05-8928-06c959724944"
23
- },
24
- "outputs": [],
25
- "source": [
26
- "import pandas as pd\n",
27
- "import numpy as np\n",
28
- "import matplotlib.pyplot as plt\n",
29
- "from sklearn.neural_network import MLPClassifier\n",
30
- "from sklearn.model_selection import train_test_split\n",
31
- "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n",
32
- "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
33
- "from sklearn.impute import SimpleImputer\n",
34
- "\n",
35
- "# Load and preprocess data\n",
36
- "df = pd.read_csv('/content/heart_disease_uci.csv')\n",
37
- "\n",
38
- "# Data preprocessing\n",
39
- "numeric_cols = ['age', 'trestbps', 'chol', 'thalch', 'oldpeak']\n",
40
- "categorical_cols = ['sex', 'cp', 'fbs', 'restecg', 'exang', 'slope', 'ca', 'thal']\n",
41
- "\n",
42
- "# Impute missing values\n",
43
- "imputer_num = SimpleImputer(strategy='median')\n",
44
- "df[numeric_cols] = imputer_num.fit_transform(df[numeric_cols])\n",
45
- "\n",
46
- "imputer_cat = SimpleImputer(strategy='most_frequent')\n",
47
- "df[categorical_cols] = imputer_cat.fit_transform(df[categorical_cols])\n",
48
- "\n",
49
- "# Encode categorical variables\n",
50
- "for col in categorical_cols:\n",
51
- " le = LabelEncoder()\n",
52
- " df[col] = le.fit_transform(df[col].astype(str))\n",
53
- "\n",
54
- "# Target variable\n",
55
- "df['target'] = (df['num'] > 0).astype(int)\n",
56
- "\n",
57
- "# Select features and target\n",
58
- "features = numeric_cols + categorical_cols\n",
59
- "X = df[features]\n",
60
- "y = df['target']\n",
61
- "\n",
62
- "# Split data\n",
63
- "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n",
64
- "\n",
65
- "# Standardize features\n",
66
- "scaler = StandardScaler()\n",
67
- "X_train = scaler.fit_transform(X_train)\n",
68
- "X_test = scaler.transform(X_test)\n",
69
- "\n",
70
- "## Experiment 10: Regularization Techniques\n",
71
- "\n",
72
- "# Best architecture from Experiment 9\n",
73
- "best_architecture = (20, 10)\n",
74
- "\n",
75
- "def evaluate_regularized_model(regularization_params):\n",
76
- " # Remove 'name' key if present\n",
77
- " params = {k:v for k,v in regularization_params.items() if k != \"name\"}\n",
78
- "\n",
79
- " # For dropout simulation, we'll adjust alpha instead\n",
80
- " if \"dropout\" in params:\n",
81
- " # In scikit-learn, we can simulate dropout effect by increasing alpha\n",
82
- " params[\"alpha\"] = params.pop(\"dropout\") * 10 # Scaling factor\n",
83
- " params[\"solver\"] = \"adam\" # Adam works better with this approach\n",
84
- "\n",
85
- " model = MLPClassifier(hidden_layer_sizes=best_architecture,\n",
86
- " activation='relu',\n",
87
- " max_iter=500,\n",
88
- " random_state=42,\n",
89
- " **params)\n",
90
- " model.fit(X_train, y_train)\n",
91
- " y_pred = model.predict(X_test)\n",
92
- " accuracy = accuracy_score(y_test, y_pred)\n",
93
- " return accuracy, model.loss_curve_\n",
94
- "\n",
95
- "# Test different regularization techniques\n",
96
- "regularization_tests = [\n",
97
- " {\"name\": \"No Regularization\", \"alpha\": 0},\n",
98
- " {\"alpha\": 0.0001, \"name\": \"L2 (alpha=0.0001)\"},\n",
99
- " {\"alpha\": 0.001, \"name\": \"L2 (alpha=0.001)\"},\n",
100
- " {\"alpha\": 0.01, \"name\": \"L2 (alpha=0.01)\"},\n",
101
- " {\"early_stopping\": True, \"validation_fraction\": 0.2, \"name\": \"Early Stopping\"},\n",
102
- " {\"alpha\": 0.001, \"early_stopping\": True, \"name\": \"L2 + Early Stopping\"},\n",
103
- " {\"dropout\": 0.2, \"name\": \"Simulated Dropout (alpha=2)\"},\n",
104
- " {\"alpha\": 0.001, \"early_stopping\": True, \"solver\": \"adam\", \"name\": \"L2 + Early Stop + Adam\"}\n",
105
- "]\n",
106
- "\n",
107
- "results = []\n",
108
- "loss_curves = []\n",
109
- "\n",
110
- "for reg_test in regularization_tests:\n",
111
- " accuracy, loss_curve = evaluate_regularized_model(reg_test)\n",
112
- " results.append({\n",
113
- " \"Regularization\": reg_test[\"name\"],\n",
114
- " \"Accuracy\": accuracy\n",
115
- " })\n",
116
- " loss_curves.append((reg_test[\"name\"], loss_curve))\n",
117
- "\n",
118
- " print(f\"\\nRegularization: {reg_test['name']}\")\n",
119
- " print(\"Classification Report:\")\n",
120
- " model_params = {k:v for k,v in reg_test.items() if k not in [\"name\", \"dropout\"]}\n",
121
- " if \"dropout\" in reg_test:\n",
122
- " model_params[\"alpha\"] = reg_test[\"dropout\"] * 10\n",
123
- " model = MLPClassifier(hidden_layer_sizes=st_architecture,\n",
124
- " activation='relu',\n",
125
- " max_iter=500,\n",
126
- " random_state=42,\n",
127
- " **model_params)\n",
128
- " model.fit(X_train, y_train)\n",
129
- " y_pred = model.predict(X_test)\n",
130
- " print(classification_report(y_test, y_pred))\n",
131
- " print(\"Confusion Matrix:\")\n",
132
- " print(confusion_matrix(y_test, y_pred))\n",
133
- "\n",
134
- "# Display results\n",
135
- "results_df = pd.DataFrame(results)\n",
136
- "print(\"\\nSummary of Regularization Results:\")\n",
137
- "print(results_df.sort_values(by=\"Accuracy\", ascending=False))\n",
138
- "\n",
139
- "# Visualization\n",
140
- "plt.figure(figsize=(14, 6))\n",
141
- "\n",
142
- "# Accuracy comparison\n",
143
- "plt.subplot(1, 2, 1)\n",
144
- "plt.barh(results_df['Regularization'], results_df['Accuracy'], color='lightgreen')\n",
145
- "plt.title('Test Accuracy by Regularization Technique')\n",
146
- "plt.xlabel('Accuracy')\n",
147
- "plt.xlim(0.7, 0.9)\n",
148
- "\n",
149
- "# Training loss curves\n",
150
- "plt.subplot(1, 2, 2)\n",
151
- "for name, curve in loss_curves:\n",
152
- " plt.plot(curve, label=name)\n",
153
- "plt.title('Training Loss with Regularization')\n",
154
- "plt.xlabel('Iterations')\n",
155
- "plt.ylabel('Loss')\n",
156
- "plt.legend()\n",
157
- "plt.grid()\n",
158
- "\n",
159
- "plt.tight_layout()\n",
160
- "plt.show()"
161
- ]
162
- }
163
- ],
164
- "metadata": {
165
- "colab": {
166
- "authorship_tag": "ABX9TyNefA49SOjY7QnPMPjmtmQE",
167
- "provenance": []
168
- },
169
- "kernelspec": {
170
- "display_name": "Python 3 (ipykernel)",
171
- "language": "python",
172
- "name": "python3"
173
- },
174
- "language_info": {
175
- "codemirror_mode": {
176
- "name": "ipython",
177
- "version": 3
178
- },
179
- "file_extension": ".py",
180
- "mimetype": "text/x-python",
181
- "name": "python",
182
- "nbconvert_exporter": "python",
183
- "pygments_lexer": "ipython3",
184
- "version": "3.12.4"
185
- }
186
- },
187
- "nbformat": 4,
188
- "nbformat_minor": 4
189
- }
@@ -1,197 +0,0 @@
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": 15796,
13
- "status": "ok",
14
- "timestamp": 1743486879713,
15
- "user": {
16
- "displayName": "Jaison A",
17
- "userId": "07006398627763032071"
18
- },
19
- "user_tz": -330
20
- },
21
- "id": "S919d8O06g3w",
22
- "outputId": "a9c34590-8cf2-4bcc-de16-ebbea74d63b7"
23
- },
24
- "outputs": [],
25
- "source": [
26
- "import pandas as pd\n",
27
- "import numpy as np\n",
28
- "import matplotlib.pyplot as plt\n",
29
- "from sklearn.neural_network import MLPClassifier\n",
30
- "from sklearn.model_selection import train_test_split\n",
31
- "from sklearn.metrics import classification_report, confusion_matrix, accuracy_score\n",
32
- "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
33
- "from sklearn.impute import SimpleImputer\n",
34
- "\n",
35
- "# Load dataset\n",
36
- "df = pd.read_csv('/content/heart_disease_uci.csv')\n",
37
- "\n",
38
- "# Data preprocessing\n",
39
- "# Handle missing values - fill numeric with median, categorical with mode\n",
40
- "numeric_cols = ['age', 'trestbps', 'chol', 'thalch', 'oldpeak']\n",
41
- "categorical_cols = ['sex', 'cp', 'fbs', 'restecg', 'exang', 'slope', 'ca', 'thal']\n",
42
- "\n",
43
- "# Impute missing values\n",
44
- "imputer_num = SimpleImputer(strategy='median')\n",
45
- "df[numeric_cols] = imputer_num.fit_transform(df[numeric_cols])\n",
46
- "\n",
47
- "imputer_cat = SimpleImputer(strategy='most_frequent')\n",
48
- "df[categorical_cols] = imputer_cat.fit_transform(df[categorical_cols])\n",
49
- "\n",
50
- "# Encode categorical variables\n",
51
- "label_encoders = {}\n",
52
- "for col in categorical_cols:\n",
53
- " le = LabelEncoder()\n",
54
- " df[col] = le.fit_transform(df[col].astype(str)) # Convert to string before encoding\n",
55
- " label_encoders[col] = le\n",
56
- "\n",
57
- "# Target variable - assuming 'num' is the target (0 = no disease, >0 = disease)\n",
58
- "df['target'] = (df['num'] > 0).astype(int)\n",
59
- "\n",
60
- "# Select features and target\n",
61
- "features = numeric_cols + categorical_cols\n",
62
- "X = df[features]\n",
63
- "y = df['target']\n",
64
- "\n",
65
- "# Split data\n",
66
- "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n",
67
- "\n",
68
- "# Standardize features\n",
69
- "scaler = StandardScaler()\n",
70
- "X_train = scaler.fit_transform(X_train)\n",
71
- "X_test = scaler.transform(X_test)\n",
72
- "\n",
73
- "# Function to evaluate different configurations\n",
74
- "def evaluate_model(hidden_layer_sizes, activation, max_iter=500):\n",
75
- " model = MLPClassifier(hidden_layer_sizes=hidden_layer_sizes,\n",
76
- " activation=activation,\n",
77
- " max_iter=max_iter,\n",
78
- " random_state=42)\n",
79
- " model.fit(X_train, y_train)\n",
80
- " y_pred = model.predict(X_test)\n",
81
- " accuracy = accuracy_score(y_test, y_pred)\n",
82
- " return accuracy, model.loss_curve_\n",
83
- "\n",
84
- "# Test different configurations\n",
85
- "configurations = [\n",
86
- " {\"hidden\": (10,), \"activation\": \"relu\", \"name\": \"Single(10) - ReLU\"},\n",
87
- " {\"hidden\": (30,), \"activation\": \"tanh\", \"name\": \"Single(30) - Tanh\"},\n",
88
- " {\"hidden\": (10, 10), \"activation\": \"relu\", \"name\": \"Double(10,10) - ReLU\"},\n",
89
- " {\"hidden\": (20, 10), \"activation\": \"logistic\", \"name\": \"Double(20,10) - Logistic\"},\n",
90
- " {\"hidden\": (10, 5, 3), \"activation\": \"relu\", \"name\": \"Triple(10,5,3) - ReLU\"},\n",
91
- " {\"hidden\": (20, 15, 10), \"activation\": \"tanh\", \"name\": \"Triple(20,15,10) - Tanh\"},\n",
92
- "]\n",
93
- "\n",
94
- "results = []\n",
95
- "loss_curves = []\n",
96
- "\n",
97
- "for config in configurations:\n",
98
- " accuracy, loss_curve = evaluate_model(config[\"hidden\"], config[\"activation\"])\n",
99
- " results.append({\n",
100
- " \"Configuration\": config[\"name\"],\n",
101
- " \"Accuracy\": accuracy,\n",
102
- " \"Activation\": config[\"activation\"],\n",
103
- " \"Architecture\": str(config[\"hidden\"])\n",
104
- " })\n",
105
- " loss_curves.append((config[\"name\"], loss_curve))\n",
106
- "\n",
107
- " # Print detailed report for each configuration\n",
108
- " print(f\"\\nConfiguration: {config['name']}\")\n",
109
- " print(\"Classification Report:\")\n",
110
- " model = MLPClassifier(hidden_layer_sizes=config[\"hidden\"],\n",
111
- " activation=config[\"activation\"],\n",
112
- " max_iter=500,\n",
113
- " random_state=42)\n",
114
- " model.fit(X_train, y_train)\n",
115
- " y_pred = model.predict(X_test)\n",
116
- " print(classification_report(y_test, y_pred))\n",
117
- " print(\"Confusion Matrix:\")\n",
118
- " print(confusion_matrix(y_test, y_pred))\n",
119
- "\n",
120
- "# Display results\n",
121
- "results_df = pd.DataFrame(results)\n",
122
- "print(\"\\nSummary of Results:\")\n",
123
- "print(results_df.sort_values(by=\"Accuracy\", ascending=False))\n",
124
- "\n",
125
- "# Visualization\n",
126
- "plt.figure(figsize=(14, 6))\n",
127
- "\n",
128
- "# Accuracy comparison\n",
129
- "plt.subplot(1, 2, 1)\n",
130
- "plt.barh(results_df['Configuration'], results_df['Accuracy'], color='skyblue')\n",
131
- "plt.title('Test Accuracy by Configuration')\n",
132
- "plt.xlabel('Accuracy')\n",
133
- "plt.xlim(0.7, 0.9)\n",
134
- "\n",
135
- "# Training loss curves\n",
136
- "plt.subplot(1, 2, 2)\n",
137
- "for name, curve in loss_curves:\n",
138
- " plt.plot(curve, label=name)\n",
139
- "plt.title('Training Loss Across Configurations')\n",
140
- "plt.xlabel('Iterations')\n",
141
- "plt.ylabel('Loss')\n",
142
- "plt.legend()\n",
143
- "plt.grid()\n",
144
- "\n",
145
- "plt.tight_layout()\n",
146
- "plt.show()\n",
147
- "\n",
148
- "# Feature importance analysis (using weights from the best model)\n",
149
- "best_config_idx = np.argmax(results_df['Accuracy'])\n",
150
- "best_model = MLPClassifier(hidden_layer_sizes=configurations[best_config_idx][\"hidden\"],\n",
151
- " activation=configurations[best_config_idx][\"activation\"],\n",
152
- " max_iter=500,\n",
153
- " random_state=42)\n",
154
- "best_model.fit(X_train, y_train)\n",
155
- "\n",
156
- "# Get the weights from input to first hidden layer\n",
157
- "if len(best_model.coefs_) > 0:\n",
158
- " input_weights = best_model.coefs_[0]\n",
159
- " feature_importance = np.mean(np.abs(input_weights), axis=1)\n",
160
- "\n",
161
- " plt.figure(figsize=(10, 6))\n",
162
- " plt.barh(features, feature_importance)\n",
163
- " plt.title('Feature Importance (Average Absolute Weight)')\n",
164
- " plt.xlabel('Importance')\n",
165
- " plt.tight_layout()\n",
166
- " plt.show()\n",
167
- "else:\n",
168
- " print(\"Could not extract feature importance - model weights not available\")"
169
- ]
170
- }
171
- ],
172
- "metadata": {
173
- "colab": {
174
- "authorship_tag": "ABX9TyPivrGG2d31eEVHX9BuG3D8",
175
- "provenance": []
176
- },
177
- "kernelspec": {
178
- "display_name": "Python 3 (ipykernel)",
179
- "language": "python",
180
- "name": "python3"
181
- },
182
- "language_info": {
183
- "codemirror_mode": {
184
- "name": "ipython",
185
- "version": 3
186
- },
187
- "file_extension": ".py",
188
- "mimetype": "text/x-python",
189
- "name": "python",
190
- "nbconvert_exporter": "python",
191
- "pygments_lexer": "ipython3",
192
- "version": "3.12.4"
193
- }
194
- },
195
- "nbformat": 4,
196
- "nbformat_minor": 4
197
- }