fschwartzer commited on
Commit
b66c2b6
·
1 Parent(s): b55fce9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  import statsmodels.api as sm
4
  import numpy as np
5
  import matplotlib.pyplot as plt
 
6
  from itertools import product
7
 
8
  # Function to apply transformations to both features and target
@@ -66,25 +67,29 @@ def load_excel(file):
66
 
67
  # Plot 1: Transformed_target vs. Predicted values
68
  predicted = model.predict(transformed_features)
69
- axes[0].scatter(transformed_target, predicted)
70
- axes[0].set_title('Transformed_target vs. Predicted')
71
- axes[0].set_xlabel('Transformed_target')
72
- axes[0].set_ylabel('Predicted')
 
 
 
 
73
 
74
  # Plot 2: Residuals
75
  residuals = model.resid
76
- axes[1].hist(residuals, bins=30, edgecolor='k')
77
- axes[1].set_title('Residuals Histogram')
78
- axes[1].set_xlabel('Residuals')
79
- axes[1].set_ylabel('Frequency')
80
 
81
  # Create a table for residuals
82
  residuals_table = pd.DataFrame({'Residuals': residuals})
83
 
84
  results.append({
85
  'best_equation': model.summary().as_text(),
86
- 'plot_transformed_vs_predicted': fig, # Use the figure object
87
- 'plot_residuals_histogram': fig, # Use the figure object
88
  'residuals_table': residuals_table
89
  })
90
 
@@ -96,10 +101,10 @@ iface = gr.Interface(
96
  fn=load_excel,
97
  inputs="file",
98
  outputs=[
99
- gr.Textbox(label="Best Equation", type="text"),
100
- gr.Plot(label="Transformed_target vs. Predicted", type="plot"),
101
- gr.Plot(label="Residuals Histogram", type="plot"),
102
- gr.DataFrame(label="Residuals Table", type="pandas"),
103
  ],
104
  live=False,
105
  theme=gr.themes.Monochrome(),
 
3
  import statsmodels.api as sm
4
  import numpy as np
5
  import matplotlib.pyplot as plt
6
+ import seaborn as sns
7
  from itertools import product
8
 
9
  # Function to apply transformations to both features and target
 
67
 
68
  # Plot 1: Transformed_target vs. Predicted values
69
  predicted = model.predict(transformed_features)
70
+ plt.figure(figsize=(18, 6))
71
+ sns.scatterplot(x=transformed_target, y=predicted)
72
+ plt.xlabel("Observados")
73
+ plt.ylabel("Previstos")
74
+ plt.tight_layout()
75
+ plt.plot(X_plot, Y_plot, color='r')
76
+ plt.savefig("scatterplot.png")
77
+ plt.close()
78
 
79
  # Plot 2: Residuals
80
  residuals = model.resid
81
+ plt.figure(figsize=(18, 6))
82
+ sns.histplot(data = residuals, kde=True)
83
+ plt.savefig("histplot.png")
84
+ plt.close()
85
 
86
  # Create a table for residuals
87
  residuals_table = pd.DataFrame({'Residuals': residuals})
88
 
89
  results.append({
90
  'best_equation': model.summary().as_text(),
91
+ 'plot_transformed_vs_predicted': "scatterplot.png", # Use the figure object
92
+ 'plot_residuals_histogram': "histplot.png", # Use the figure object
93
  'residuals_table': residuals_table
94
  })
95
 
 
101
  fn=load_excel,
102
  inputs="file",
103
  outputs=[
104
+ gr.Textbox(label="Resultados Estatísticos", type="text"),
105
+ gr.Image(label="Gráfico - Observados X Previstos"),
106
+ gr.Image(label="Histograma de Resíduos"),
107
+ gr.DataFrame(label="Tabela dos Resíduos", type="pandas"),
108
  ],
109
  live=False,
110
  theme=gr.themes.Monochrome(),