-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7_main.py
More file actions
267 lines (210 loc) · 8.39 KB
/
7_main.py
File metadata and controls
267 lines (210 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import sys
import time
import importlib
from datetime import datetime
# Import summary report module
summary_report = importlib.import_module('7_summary_report')
save_experiment_results = summary_report.save_experiment_results
generate_unified_comparison_report = summary_report.generate_unified_comparison_report
# Import unified visualizations module
unified_viz = importlib.import_module('7_unified_visualizations')
def print_header():
"""Print header"""
print("\n" + "="*80)
print(" " * 15 + "REGULARIZATION TECHNIQUES COMPARATIVE STUDY")
print(" " * 30 + "Group 7 - ML Project")
print("="*80)
print("\nGroup Members:")
print(" - S20230010014 - Aman Raj (Leader)")
print(" - S20230010251 - Vanya Awasthi")
print(" - S20230010011 - Ala Sai Teja")
print(" - S20230010095 - Grandhe Bhanu Sishya Naga Vihari")
print("="*80 + "\n")
def print_menu():
"""Print menu options"""
print("\nAvailable Experiments:")
print("="*80)
print("1. Logistic Regression with L2 (Ridge) Regularization")
print(" Dataset: Breast Cancer Wisconsin Diagnostic")
print()
print("2. Logistic Regression with L1 (Lasso) Regularization")
print(" Dataset: SPECTF Heart")
print()
print("3. Logistic Regression with Elastic Net Regularization")
print(" Dataset: Breast Cancer Wisconsin Diagnostic")
print()
print("4. Neural Network with Dropout Regularization")
print(" Dataset: ILPD Indian Liver Patient")
print()
print("5. Neural Network with Early Stopping")
print(" Dataset: ILPD Indian Liver Patient")
print()
print("6. Run ALL experiments (this will take time)")
print()
print("7. Generate Unified Comparison Report")
print(" View comprehensive analysis of all experiments")
print()
print("0. Exit")
print("="*80)
def run_l2_experiment():
"""Run L2 regularization experiment"""
print("\nRunning L2 (Ridge) Regularization Experiment...")
start_time = time.time()
try:
# Import and run
module = importlib.import_module('7_logistic_regression_l2')
module.main()
elapsed = time.time() - start_time
print(f"\nL2 experiment completed in {elapsed:.2f} seconds")
return True
except Exception as e:
print(f"\nError running L2 experiment: {str(e)}")
return False
def run_l1_experiment():
"""Run L1 regularization experiment"""
print("\nRunning L1 (Lasso) Regularization Experiment...")
start_time = time.time()
try:
module = importlib.import_module('7_logistic_regression_l1')
module.main()
elapsed = time.time() - start_time
print(f"\nL1 experiment completed in {elapsed:.2f} seconds")
return True
except Exception as e:
print(f"\nError running L1 experiment: {str(e)}")
return False
def run_elastic_net_experiment():
"""Run Elastic Net regularization experiment"""
print("\nRunning Elastic Net Regularization Experiment...")
start_time = time.time()
try:
module = importlib.import_module('7_logistic_regression_elastic_net')
module.main()
elapsed = time.time() - start_time
print(f"\nElastic Net experiment completed in {elapsed:.2f} seconds")
return True
except Exception as e:
print(f"\nError running Elastic Net experiment: {str(e)}")
return False
def run_dropout_experiment():
"""Run Dropout regularization experiment"""
print("\nRunning Dropout Regularization Experiment...")
start_time = time.time()
try:
module = importlib.import_module('7_neural_network_dropout')
module.main()
elapsed = time.time() - start_time
print(f"\nDropout experiment completed in {elapsed:.2f} seconds")
return True
except Exception as e:
print(f"\nError running Dropout experiment: {str(e)}")
return False
def run_early_stopping_experiment():
"""Run Early Stopping experiment"""
print("\nRunning Early Stopping Experiment...")
start_time = time.time()
try:
module = importlib.import_module('7_neural_network_early_stopping')
module.main()
elapsed = time.time() - start_time
print(f"\nEarly Stopping experiment completed in {elapsed:.2f} seconds")
return True
except Exception as e:
print(f"\nError running Early Stopping experiment: {str(e)}")
return False
def run_all_experiments():
"""Run all experiments"""
print("\nRunning ALL Experiments (this will take several minutes)...")
total_start = time.time()
results = []
experiments = [
("L2 Regularization", run_l2_experiment),
("L1 Regularization", run_l1_experiment),
("Elastic Net", run_elastic_net_experiment),
("Dropout", run_dropout_experiment),
("Early Stopping", run_early_stopping_experiment),
]
for name, func in experiments:
print(f"\n[{name}]")
success = func()
results.append((name, success))
if not success:
response = input("\nExperiment failed. Continue with remaining experiments? (y/n): ")
if response.lower() != 'y':
break
total_elapsed = time.time() - total_start
# Summary
print("\n" + "="*80)
print("EXECUTION SUMMARY")
print("="*80)
print(f"Total execution time: {total_elapsed:.2f} seconds ({total_elapsed/60:.2f} minutes)")
print("\nResults:")
for name, success in results:
status = "SUCCESS" if success else "FAILED"
print(f" {status}: {name}")
print("="*80)
def run_unified_visualizations():
"""Run unified visualizations for all regularization techniques"""
print("\nGenerating Unified Comparison Visualizations...")
print("This will train all models and create comprehensive comparison plots...")
start_time = time.time()
try:
# Run the unified visualizations main function
unified_viz.main()
elapsed = time.time() - start_time
print(f"\nUnified visualizations completed in {elapsed:.2f} seconds ({elapsed/60:.2f} minutes)")
return True
except Exception as e:
print(f"\nError generating unified visualizations: {str(e)}")
import traceback
traceback.print_exc()
return False
def main():
"""Main function"""
print_menu()
while True:
print_menu()
try:
choice = input("\nEnter your choice (0-7): ").strip()
if choice == '0':
print("\nExiting... Thank you!")
sys.exit(0)
elif choice == '1':
run_l2_experiment()
elif choice == '2':
run_l1_experiment()
elif choice == '3':
run_elastic_net_experiment()
elif choice == '4':
run_dropout_experiment()
elif choice == '5':
run_early_stopping_experiment()
elif choice == '6':
confirm = input("\nThis will run all experiments and may take 15-30 minutes. Continue? (y/n): ")
if confirm.lower() == 'y':
run_all_experiments()
else:
print("Cancelled.")
elif choice == '7':
confirm = input("\nThis will train all models and generate unified visualizations. Continue? (y/n): ")
if confirm.lower() == 'y':
run_unified_visualizations()
else:
print("Cancelled.")
else:
print("\nInvalid choice. Please enter a number between 0 and 7.")
# Ask if user wants to continue
response = input("\n\nPress Enter to return to menu or 'q' to quit: ").strip()
if response.lower() == 'q':
print("\nExiting... Thank you!")
sys.exit(0)
except KeyboardInterrupt:
print("\n\nInterrupted by user. Exiting...")
sys.exit(0)
except Exception as e:
print(f"\nUnexpected error: {str(e)}")
response = input("Continue? (y/n): ")
if response.lower() != 'y':
sys.exit(1)
if __name__ == "__main__":
main()