Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -5
src/streamlit_app.py
CHANGED
|
@@ -95,6 +95,9 @@ usar_logy = st.sidebar.checkbox("Aplicar transformação log(SalePrice) caso pre
|
|
| 95 |
teste_size = st.sidebar.slider("Proporção de teste (holdout)", 0.1, 0.5, 0.2, 0.05)
|
| 96 |
alpha_reg = st.sidebar.slider("Nível de significância (α) — Regressão", 0.01, 0.10, 0.05, 0.01)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
# -------------------------------------------------
|
| 99 |
# Conteúdo principal — Análises
|
| 100 |
# -------------------------------------------------
|
|
@@ -113,9 +116,9 @@ variavel = st.selectbox(
|
|
| 113 |
["Neighborhood","Garage_Type","Fireplaces"]
|
| 114 |
)
|
| 115 |
if not dados_filtrados.empty and len(dados_filtrados[variavel].dropna().unique()) > 1:
|
| 116 |
-
fig2, ax2 = plt.subplots(figsize=(
|
| 117 |
sns.boxplot(x=variavel, y="SalePrice", data=dados_filtrados, ax=ax2)
|
| 118 |
-
plt.xticks(rotation=
|
| 119 |
st.pyplot(fig2, clear_figure=True, use_container_width=False)
|
| 120 |
|
| 121 |
# Scatter interativo
|
|
@@ -133,7 +136,7 @@ if not dados_filtrados.empty:
|
|
| 133 |
size='count', color='Neighborhood',
|
| 134 |
labels={'mean_price': 'Preço Médio de Venda', 'Neighborhood':'Bairro'}
|
| 135 |
)
|
| 136 |
-
fig3.update_layout(width=
|
| 137 |
st.plotly_chart(fig3, use_container_width=False)
|
| 138 |
|
| 139 |
# =================================================
|
|
@@ -148,7 +151,7 @@ def construir_formula(y, feats_num, feats_cat, inter_1=None, inter_2=None):
|
|
| 148 |
rhs = " + ".join(termos) if termos else "1"
|
| 149 |
return f"{y} ~ {rhs}"
|
| 150 |
|
| 151 |
-
if
|
| 152 |
cols_necessarias = ['SalePrice'] + feats_num + feats_cat
|
| 153 |
if interagir and inter_1 and inter_2:
|
| 154 |
cols_necessarias += [inter_1, inter_2]
|
|
@@ -175,7 +178,7 @@ if st.button("Ajustar modelo"):
|
|
| 175 |
})
|
| 176 |
st.dataframe(metrics, use_container_width=False, height=120)
|
| 177 |
|
| 178 |
-
# Gráficos diagnósticos
|
| 179 |
residuos, fitted = model.resid, model.fittedvalues
|
| 180 |
cols = st.columns(3)
|
| 181 |
with cols[0]:
|
|
|
|
| 95 |
teste_size = st.sidebar.slider("Proporção de teste (holdout)", 0.1, 0.5, 0.2, 0.05)
|
| 96 |
alpha_reg = st.sidebar.slider("Nível de significância (α) — Regressão", 0.01, 0.10, 0.05, 0.01)
|
| 97 |
|
| 98 |
+
# >>> botão agora na sidebar <<<
|
| 99 |
+
ajustar = st.sidebar.button("Ajustar modelo")
|
| 100 |
+
|
| 101 |
# -------------------------------------------------
|
| 102 |
# Conteúdo principal — Análises
|
| 103 |
# -------------------------------------------------
|
|
|
|
| 116 |
["Neighborhood","Garage_Type","Fireplaces"]
|
| 117 |
)
|
| 118 |
if not dados_filtrados.empty and len(dados_filtrados[variavel].dropna().unique()) > 1:
|
| 119 |
+
fig2, ax2 = plt.subplots(figsize=(5,3.5))
|
| 120 |
sns.boxplot(x=variavel, y="SalePrice", data=dados_filtrados, ax=ax2)
|
| 121 |
+
plt.xticks(rotation=60)
|
| 122 |
st.pyplot(fig2, clear_figure=True, use_container_width=False)
|
| 123 |
|
| 124 |
# Scatter interativo
|
|
|
|
| 136 |
size='count', color='Neighborhood',
|
| 137 |
labels={'mean_price': 'Preço Médio de Venda', 'Neighborhood':'Bairro'}
|
| 138 |
)
|
| 139 |
+
fig3.update_layout(width=550, height=320)
|
| 140 |
st.plotly_chart(fig3, use_container_width=False)
|
| 141 |
|
| 142 |
# =================================================
|
|
|
|
| 151 |
rhs = " + ".join(termos) if termos else "1"
|
| 152 |
return f"{y} ~ {rhs}"
|
| 153 |
|
| 154 |
+
if ajustar: # botão na sidebar
|
| 155 |
cols_necessarias = ['SalePrice'] + feats_num + feats_cat
|
| 156 |
if interagir and inter_1 and inter_2:
|
| 157 |
cols_necessarias += [inter_1, inter_2]
|
|
|
|
| 178 |
})
|
| 179 |
st.dataframe(metrics, use_container_width=False, height=120)
|
| 180 |
|
| 181 |
+
# Gráficos diagnósticos compactos
|
| 182 |
residuos, fitted = model.resid, model.fittedvalues
|
| 183 |
cols = st.columns(3)
|
| 184 |
with cols[0]:
|