Update src/streamlit_app.py
Browse files- src/streamlit_app.py +51 -1
src/streamlit_app.py
CHANGED
|
@@ -22,6 +22,12 @@ from sklearn.linear_model import LogisticRegression
|
|
| 22 |
# Configuração da página do Streamlit
|
| 23 |
st.set_page_config(layout="wide", page_title="Previsão de Reclamações de Clientes")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
st.title("📊 Previsão de Reclamações de Clientes com Modelos Supervisionados")
|
| 26 |
st.markdown(
|
| 27 |
"Este dashboard tem como objetivo identificar clientes com maior probabilidade de terem feito uma reclamação nos últimos 2 anos, utilizando modelos de Machine Learning.")
|
|
@@ -255,7 +261,7 @@ tab1, tab2, tab3, tab4, tab5 = st.tabs([
|
|
| 255 |
])
|
| 256 |
|
| 257 |
with tab1:
|
| 258 |
-
st.header("
|
| 259 |
st.subheader("Primeiras 5 Linhas do Dataset")
|
| 260 |
st.dataframe(df.head())
|
| 261 |
|
|
@@ -268,6 +274,41 @@ with tab1:
|
|
| 268 |
s = buffer.getvalue()
|
| 269 |
st.text(s)
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
st.subheader("Distribuição da Variável Alvo ('Complain') Original")
|
| 272 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 273 |
sns.countplot(x=y, ax=ax)
|
|
@@ -278,6 +319,15 @@ with tab1:
|
|
| 278 |
st.write(f"Distribuição da variável 'Complain' original: {Counter(y)}")
|
| 279 |
st.warning("Observe o desbalanceamento da classe 'Complain' (poucas reclamações).")
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
with tab2:
|
| 282 |
st.header("2. Balanceamento de Dados com SMOTE")
|
| 283 |
st.write(
|
|
|
|
| 22 |
# Configuração da página do Streamlit
|
| 23 |
st.set_page_config(layout="wide", page_title="Previsão de Reclamações de Clientes")
|
| 24 |
|
| 25 |
+
st.markdown("""
|
| 26 |
+
<div style='background-color: #f0f2f6; padding: 10px; border-radius: 8px; margin-bottom: 15px;'>
|
| 27 |
+
<b>Autor:</b> Vinicius Salgueiro Costa <b>Matrícula:</b> 180028880
|
| 28 |
+
</div>
|
| 29 |
+
""", unsafe_allow_html=True)
|
| 30 |
+
|
| 31 |
st.title("📊 Previsão de Reclamações de Clientes com Modelos Supervisionados")
|
| 32 |
st.markdown(
|
| 33 |
"Este dashboard tem como objetivo identificar clientes com maior probabilidade de terem feito uma reclamação nos últimos 2 anos, utilizando modelos de Machine Learning.")
|
|
|
|
| 261 |
])
|
| 262 |
|
| 263 |
with tab1:
|
| 264 |
+
st.header("Visão Geral dos Dados")
|
| 265 |
st.subheader("Primeiras 5 Linhas do Dataset")
|
| 266 |
st.dataframe(df.head())
|
| 267 |
|
|
|
|
| 274 |
s = buffer.getvalue()
|
| 275 |
st.text(s)
|
| 276 |
|
| 277 |
+
# NOVO: Análise de valores ausentes
|
| 278 |
+
st.subheader("Valores Ausentes por Coluna")
|
| 279 |
+
missing = df.isnull().sum()
|
| 280 |
+
missing = missing[missing > 0]
|
| 281 |
+
if not missing.empty:
|
| 282 |
+
st.dataframe(missing.to_frame('Nulos'))
|
| 283 |
+
else:
|
| 284 |
+
st.info("Não há valores ausentes no dataset original.")
|
| 285 |
+
|
| 286 |
+
# NOVO: Distribuição de variáveis numéricas
|
| 287 |
+
num_cols = df_processed.select_dtypes(include=np.number).columns.tolist()
|
| 288 |
+
if num_cols:
|
| 289 |
+
st.subheader("Distribuição de Variáveis Numéricas")
|
| 290 |
+
selected_num = st.selectbox("Escolha uma variável numérica para visualizar:", num_cols, key="num_hist")
|
| 291 |
+
fig, ax = plt.subplots()
|
| 292 |
+
sns.histplot(df_processed[selected_num], kde=True, ax=ax)
|
| 293 |
+
ax.set_title(f"Distribuição de {selected_num}")
|
| 294 |
+
st.pyplot(fig)
|
| 295 |
+
|
| 296 |
+
# NOVO: Distribuição de variáveis categóricas
|
| 297 |
+
cat_cols = [col for col in df.columns if df[col].dtype == 'object']
|
| 298 |
+
if cat_cols:
|
| 299 |
+
st.subheader("Distribuição de Variáveis Categóricas")
|
| 300 |
+
selected_cat = st.selectbox("Escolha uma variável categórica para visualizar:", cat_cols, key="cat_bar")
|
| 301 |
+
fig, ax = plt.subplots()
|
| 302 |
+
df[selected_cat].value_counts().plot(kind='bar', ax=ax)
|
| 303 |
+
ax.set_title(f"Distribuição de {selected_cat}")
|
| 304 |
+
st.pyplot(fig)
|
| 305 |
+
|
| 306 |
+
# NOVO: Mapa de calor de correlação
|
| 307 |
+
st.subheader("Mapa de Calor das Correlações (variáveis numéricas)")
|
| 308 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
| 309 |
+
sns.heatmap(df_processed[num_cols].corr(), cmap='coolwarm', ax=ax, annot=False)
|
| 310 |
+
st.pyplot(fig)
|
| 311 |
+
|
| 312 |
st.subheader("Distribuição da Variável Alvo ('Complain') Original")
|
| 313 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 314 |
sns.countplot(x=y, ax=ax)
|
|
|
|
| 319 |
st.write(f"Distribuição da variável 'Complain' original: {Counter(y)}")
|
| 320 |
st.warning("Observe o desbalanceamento da classe 'Complain' (poucas reclamações).")
|
| 321 |
|
| 322 |
+
st.subheader("Comparação de Variáveis com a Variável Alvo (Complain)")
|
| 323 |
+
selected_bi = st.selectbox("Escolha uma variável para comparar com 'Complain':", num_cols)
|
| 324 |
+
fig, ax = plt.subplots()
|
| 325 |
+
sns.boxplot(x=df_processed['Complain'], y=df_processed[selected_bi], ax=ax)
|
| 326 |
+
st.pyplot(fig)
|
| 327 |
+
|
| 328 |
+
st.subheader("Resumo Estatístico Customizado")
|
| 329 |
+
st.dataframe(df_processed.describe(percentiles=[.01, .05, .25, .5, .75, .95, .99]).T)
|
| 330 |
+
|
| 331 |
with tab2:
|
| 332 |
st.header("2. Balanceamento de Dados com SMOTE")
|
| 333 |
st.write(
|