Suchinthana commited on
Commit
778ce34
·
1 Parent(s): fa2bf6e

Graph update

Browse files
Files changed (1) hide show
  1. app.py +44 -14
app.py CHANGED
@@ -29,17 +29,47 @@ def predict_and_plot(dirty, wait, lastyear, usa):
29
  # Predicting on test set for comparison
30
  y_pred = model.predict(X_test)
31
 
32
- # Plotting actual vs predicted values
33
- plt.figure(figsize=(8, 6))
34
- plt.scatter(range(len(y_test)), y_test, color='blue', label='Actual Values', alpha=0.6)
35
- plt.scatter(range(len(y_pred)), y_pred, color='red', label='Predicted Values', alpha=0.6)
36
- plt.title('Actual vs Predicted Values')
37
- plt.xlabel('Sample Index')
38
- plt.ylabel('Value')
39
- plt.legend()
40
- plt.grid(True)
41
-
42
- # Save plot to a file and display
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  plt.savefig('output_plot.png')
44
  plt.close()
45
 
@@ -50,9 +80,9 @@ with gr.Blocks() as demo:
50
  gr.Markdown("# Logistic Regression Prediction")
51
 
52
  with gr.Row():
53
- dirty_slider = gr.Slider(minimum=0, maximum=1, step=0.01, label="Dirty")
54
- wait_slider = gr.Slider(minimum=0, maximum=1, step=0.01, label="Wait")
55
- lastyear_slider = gr.Slider(minimum=0, maximum=1, step=0.01, label="Last Year")
56
  usa_slider = gr.Slider(minimum=0, maximum=1, step=0.01, label="USA")
57
 
58
  predict_button = gr.Button("Predict")
 
29
  # Predicting on test set for comparison
30
  y_pred = model.predict(X_test)
31
 
32
+ # Creating subplots for each variable and showing predicted value
33
+ fig, axs = plt.subplots(2, 2, figsize=(12, 10))
34
+
35
+ # Plot dirty variable distribution with predicted value
36
+ axs[0, 0].hist(X_test[:, 0], bins=30, color='gray', alpha=0.5, label='Dirty Distribution')
37
+ axs[0, 0].axvline(dirty, color='orange', linestyle='--', label='Input Value (Dirty)')
38
+ axs[0, 0].axvline(predicted_value, color='red', linestyle='-', label='Predicted Value')
39
+ axs[0, 0].set_title('Distribution of Dirty')
40
+ axs[0, 0].set_xlabel('Dirty')
41
+ axs[0, 0].set_ylabel('Frequency')
42
+ axs[0, 0].legend()
43
+
44
+ # Plot wait variable distribution with predicted value
45
+ axs[0, 1].hist(X_test[:, 1], bins=30, color='gray', alpha=0.5, label='Wait Distribution')
46
+ axs[0, 1].axvline(wait, color='orange', linestyle='--', label='Input Value (Wait)')
47
+ axs[0, 1].axvline(predicted_value, color='red', linestyle='-', label='Predicted Value')
48
+ axs[0, 1].set_title('Distribution of Wait')
49
+ axs[0, 1].set_xlabel('Wait')
50
+ axs[0, 1].set_ylabel('Frequency')
51
+ axs[0, 1].legend()
52
+
53
+ # Plot lastyear variable distribution with predicted value
54
+ axs[1, 0].hist(X_test[:, 2], bins=30, color='gray', alpha=0.5, label='Lastyear Distribution')
55
+ axs[1, 0].axvline(lastyear, color='orange', linestyle='--', label='Input Value (Lastyear)')
56
+ axs[1, 0].axvline(predicted_value, color='red', linestyle='-', label='Predicted Value')
57
+ axs[1, 0].set_title('Distribution of Lastyear')
58
+ axs[1, 0].set_xlabel('Lastyear')
59
+ axs[1, 0].set_ylabel('Frequency')
60
+ axs[1, 0].legend()
61
+
62
+ # Plot usa variable distribution with predicted value
63
+ axs[1, 1].hist(X_test[:, 3], bins=30, color='gray', alpha=0.5, label='USA Distribution')
64
+ axs[1, 1].axvline(usa, color='orange', linestyle='--', label='Input Value (USA)')
65
+ axs[1, 1].axvline(predicted_value, color='red', linestyle='-', label='Predicted Value')
66
+ axs[1, 1].set_title('Distribution of USA')
67
+ axs[1, 1].set_xlabel('USA')
68
+ axs[1, 1].set_ylabel('Frequency')
69
+ axs[1, 1].legend()
70
+
71
+ # Adjust layout and save the plot
72
+ plt.tight_layout()
73
  plt.savefig('output_plot.png')
74
  plt.close()
75
 
 
80
  gr.Markdown("# Logistic Regression Prediction")
81
 
82
  with gr.Row():
83
+ dirty_slider = gr.Slider(minimum=0, maximum=6, step=0.01, label="Dirty")
84
+ wait_slider = gr.Slider(minimum=0, maximum=5.3, step=0.01, label="Wait")
85
+ lastyear_slider = gr.Slider(minimum=0, maximum=70, step=0.01, label="Last Year")
86
  usa_slider = gr.Slider(minimum=0, maximum=1, step=0.01, label="USA")
87
 
88
  predict_button = gr.Button("Predict")