sanggusti commited on
Commit
04c32d6
·
1 Parent(s): 5a48f8b

Update predictive_model and requirements

Browse files
Files changed (2) hide show
  1. predictive_model.py +83 -1
  2. requirements.txt +2 -1
predictive_model.py CHANGED
@@ -66,4 +66,86 @@ def predict_readmission_risk(model, patient_data: dict) -> float:
66
  # If it's a classifier with predict_proba
67
  prob = model.predict_proba(X)[0,1]
68
  return float(prob)
69
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  # If it's a classifier with predict_proba
67
  prob = model.predict_proba(X)[0,1]
68
  return float(prob)
69
+
70
+ # Add this main function
71
+ if __name__ == "__main__":
72
+ # Set up logging
73
+ logging.basicConfig(level=logging.INFO,
74
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
75
+
76
+ print("==== Discharge Guard Readmission Risk Prediction Demo ====")
77
+
78
+ # Create test patient data
79
+ test_patients = [
80
+ {
81
+ "id": "P001",
82
+ "name": "John Doe",
83
+ "age": 45,
84
+ "num_conditions": 1,
85
+ "num_medications": 2
86
+ },
87
+ {
88
+ "id": "P002",
89
+ "name": "Jane Smith",
90
+ "age": 72,
91
+ "num_conditions": 4,
92
+ "num_medications": 7
93
+ },
94
+ {
95
+ "id": "P003",
96
+ "name": "Bob Johnson",
97
+ "age": 65,
98
+ "num_conditions": 3,
99
+ "num_medications": 5
100
+ }
101
+ ]
102
+
103
+ # Create an instance of the SimpleReadmissionModel
104
+ print("\n1. Testing SimpleReadmissionModel:")
105
+ simple_model = SimpleReadmissionModel()
106
+
107
+ # Test with each patient
108
+ for patient in test_patients:
109
+ risk_score = simple_model.predict(patient)
110
+ risk_percent = risk_score * 100
111
+ print(f" Patient {patient['id']} ({patient['name']}): Risk Score = {risk_percent:.1f}%")
112
+
113
+ # Try to create and save a sample model for demonstration
114
+ try:
115
+ from sklearn.ensemble import RandomForestClassifier
116
+ from sklearn.datasets import make_classification
117
+
118
+ print("\n2. Creating sample RandomForest model for demonstration:")
119
+ # Generate synthetic data
120
+ X, y = make_classification(n_samples=1000, n_features=3,
121
+ n_informative=3, n_redundant=0,
122
+ random_state=42)
123
+
124
+ # Create and fit a simple model
125
+ rf_model = RandomForestClassifier(n_estimators=10, random_state=42)
126
+ rf_model.fit(X, y)
127
+
128
+ # Save the model
129
+ model_path = "model.joblib"
130
+ joblib.dump(rf_model, model_path)
131
+ print(f" Sample model created and saved to {model_path}")
132
+
133
+ # Now load and use the model
134
+ loaded_model = load_model(model_path)
135
+
136
+ print("\n3. Testing loaded model predictions:")
137
+ for patient in test_patients:
138
+ risk_score = predict_readmission_risk(loaded_model, patient)
139
+ risk_percent = risk_score * 100
140
+ print(f" Patient {patient['id']} ({patient['name']}): Risk Score = {risk_percent:.1f}%")
141
+
142
+ except ImportError:
143
+ print("\nSkipping sklearn model creation (sklearn not available).")
144
+ print("Using dummy prediction function instead:")
145
+
146
+ for patient in test_patients:
147
+ risk_score = predict_readmission_risk(None, patient)
148
+ risk_percent = risk_score * 100
149
+ print(f" Patient {patient['id']} ({patient['name']}): Risk Score = {risk_percent:.1f}%")
150
+
151
+ print("\nDemo complete. Implement this model in your discharge workflow to identify high-risk patients.")
requirements.txt CHANGED
@@ -2,4 +2,5 @@ openai
2
  reportlab
3
  numpy
4
  pandas
5
- joblib
 
 
2
  reportlab
3
  numpy
4
  pandas
5
+ joblib
6
+ scikit-learn