-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_analysis.py
More file actions
143 lines (110 loc) · 5.18 KB
/
example_analysis.py
File metadata and controls
143 lines (110 loc) · 5.18 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
#!/usr/bin/env python3
"""
Example script demonstrating the improved Himalayan expedition analysis.
This script shows how to use the new modular analysis functions with
cross-validation as recommended in the project README.
Usage:
python example_analysis.py
"""
import pandas as pd
import numpy as np
from analysis_utils import load_and_analyze_expeditions, ExpeditionAnalyzer
def main():
"""Run the complete analysis pipeline with improvements."""
print("=" * 60)
print("Himalayan Expedition Success Analysis - Improved Version")
print("=" * 60)
try:
# Run the complete analysis
data, results, analyzer = load_and_analyze_expeditions()
print("\n" + "=" * 50)
print("SUMMARY OF IMPROVEMENTS")
print("=" * 50)
print("\n1. CROSS-VALIDATION RESULTS (addressing README recommendation):")
print(f" • Mean CV Accuracy: {results['cv_accuracy_mean']:.3f} "
f"(±{results['cv_accuracy_std']*2:.3f})")
print(f" • Mean CV ROC AUC: {results['cv_roc_auc_mean']:.3f} "
f"(±{results['cv_roc_auc_std']*2:.3f})")
print(" • This provides more robust performance estimates than single train-test split")
print("\n2. DATA VALIDATION:")
print(" • Automatic validation of data structure and quality")
print(" • Warnings for high missing data percentages")
print(" • Error checking for invalid values")
print("\n3. SPECIALIZED EVALUATION METRICS:")
print(f" • Peirce Skill Score (PSS): {results['pss']:.3f}")
print(f" • Heidke Skill Score (HSS): {results['hss']:.3f}")
print(" • These are domain-appropriate metrics for binary classification")
print("\n4. MODULAR CODE ORGANIZATION:")
print(" • Reusable ExpeditionAnalyzer class")
print(" • Separated data processing, validation, and modeling functions")
print(" • Consistent plotting and output management")
print("\n5. REPRODUCIBILITY ENHANCEMENTS:")
print(" • requirements.txt file for dependency management")
print(" • Consistent random seeds throughout analysis")
print(" • Automated testing framework")
print("\nCompare these results with the original notebook analysis:")
print(f" Original reported accuracy: ~78%")
print(f" Improved CV accuracy: {results['cv_accuracy_mean']:.1%}")
print(f" Original AUC: ~0.79")
print(f" Improved CV AUC: {results['cv_roc_auc_mean']:.3f}")
# Feature importance summary
print("\n" + "=" * 50)
print("KEY FINDINGS CONFIRMED")
print("=" * 50)
# Get top features (would need feature ranking from analysis)
X = data.drop(columns=['success'])
y = data['success']
feature_ranking = analyzer.rank_features(X, y)
print("\nTop 5 most important features:")
for i, (_, row) in enumerate(feature_ranking.head().iterrows()):
print(f" {i+1}. {row['Feature']}: F-score = {row['F-Score']:.2f}")
print("\nThese findings support the original conclusions about:")
print(" • Importance of supplemental oxygen use")
print(" • Effect of route standardization")
print(" • Seasonal climbing patterns")
except FileNotFoundError:
print("ERROR: data/expeditions.csv not found!")
print("\nTo run this analysis, ensure you have:")
print("1. The data/expeditions.csv file in the project directory")
print("2. Installed the required dependencies: pip install -r requirements.txt")
return 1
except Exception as e:
print(f"ERROR during analysis: {e}")
return 1
print("\n" + "=" * 60)
print("Analysis complete! Check the overleaf/ directory for visualizations.")
print("=" * 60)
return 0
def demonstrate_validation():
"""Demonstrate the data validation features."""
print("\n" + "=" * 40)
print("DEMONSTRATING DATA VALIDATION")
print("=" * 40)
analyzer = ExpeditionAnalyzer()
# Create sample problematic data
problematic_data = pd.DataFrame({
'mbrs_summited': [1, 2, None, 0], # Missing value
'max_elev_reached': [8848, -100, 7000, 6000], # Negative value
'season': ['Spring', 'Winter', 'Autumn', 'Summer'],
'bad_column': [1, 2, 3, 4] # Will be filtered out
})
print("\nValidating problematic dataset:")
validation = analyzer.validate_data(problematic_data)
print("\nValidation Results:")
if validation['errors']:
print("ERRORS:")
for error in validation['errors']:
print(f" ❌ {error}")
if validation['warnings']:
print("WARNINGS:")
for warning in validation['warnings']:
print(f" ⚠️ {warning}")
if validation['info']:
print("INFO:")
for info in validation['info']:
print(f" ℹ️ {info}")
if __name__ == "__main__":
exit_code = main()
# Demonstrate additional features
demonstrate_validation()
exit(exit_code)