Update NdR_disease.py
Browse files- NdR_disease.py +29 -26
NdR_disease.py
CHANGED
@@ -196,6 +196,10 @@ def run_disease_train():
|
|
196 |
return linear_model, neural_model, scaler, conditions, num_classes
|
197 |
|
198 |
# Function to get user input and make predictions
|
|
|
|
|
|
|
|
|
199 |
def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
|
200 |
st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
|
201 |
|
@@ -214,29 +218,28 @@ def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, n
|
|
214 |
interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
|
215 |
user_features.extend([interaction_term, interaction_term2])
|
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 |
-
get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes)
|
|
|
196 |
return linear_model, neural_model, scaler, conditions, num_classes
|
197 |
|
198 |
# Function to get user input and make predictions
|
199 |
+
import streamlit as st
|
200 |
+
import numpy as np
|
201 |
+
import torch
|
202 |
+
|
203 |
def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
|
204 |
st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
|
205 |
|
|
|
218 |
interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
|
219 |
user_features.extend([interaction_term, interaction_term2])
|
220 |
|
221 |
+
# Add a button to trigger the predictions
|
222 |
+
if st.button('Calculate Predictions'):
|
223 |
+
# Normalize features
|
224 |
+
user_features = scaler.transform([user_features])
|
225 |
+
user_tensor = torch.from_numpy(user_features).float()
|
226 |
+
|
227 |
+
# Random prediction
|
228 |
+
random_pred = np.random.randint(num_classes)
|
229 |
+
st.write(f"\nRandom Prediction: {conditions[random_pred]}")
|
230 |
+
|
231 |
+
# Linear Model Prediction
|
232 |
+
linear_model.eval()
|
233 |
+
with torch.no_grad():
|
234 |
+
outputs = linear_model(user_tensor)
|
235 |
+
_, predicted = torch.max(outputs.data, 1)
|
236 |
+
linear_pred = predicted.item()
|
237 |
+
st.write(f"Linear Model Prediction: {conditions[linear_pred]}")
|
238 |
+
|
239 |
+
# Neural Network Prediction
|
240 |
+
neural_model.eval()
|
241 |
+
with torch.no_grad():
|
242 |
+
outputs = neural_model(user_tensor)
|
243 |
+
_, predicted = torch.max(outputs.data, 1)
|
244 |
+
neural_pred = predicted.item()
|
245 |
+
st.write(f"Neural Network Prediction: {conditions[neural_pred]}")
|
|