joannyvit commited on
Commit
afc6289
·
verified ·
1 Parent(s): a818339

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +73 -0
  2. readme.py +10 -0
  3. requisitos.py +7 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.preprocessing import StandardScaler
6
+ from sklearn.linear_model import LogisticRegression
7
+ from sklearn.ensemble import RandomForestClassifier
8
+ from sklearn.metrics import roc_auc_score, roc_curve, precision_score, recall_score, f1_score, confusion_matrix
9
+ from imblearn.over_sampling import SMOTE
10
+ import matplotlib.pyplot as plt
11
+
12
+ def process_file(file):
13
+ df = pd.read_csv(file.name)
14
+
15
+ return df.head().to_html()
16
+
17
+ def train_model(file, target, features, model_choice):
18
+ df = pd.read_csv(file.name)
19
+
20
+ X = df[features]
21
+ y = df[target]
22
+
23
+ sm = SMOTE()
24
+ X_res, y_res = sm.fit_resample(X, y)
25
+
26
+ X_train, X_test, y_train, y_test = train_test_split(X_res, y_res, test_size=0.2)
27
+
28
+ if model_choice == "Regressão Logística":
29
+ scaler = StandardScaler()
30
+ X_train = scaler.fit_transform(X_train)
31
+ X_test = scaler.transform(X_test)
32
+ model = LogisticRegression()
33
+ else:
34
+ model = RandomForestClassifier()
35
+
36
+ model.fit(X_train, y_train)
37
+ y_pred = model.predict(X_test)
38
+ y_proba = model.predict_proba(X_test)[:, 1]
39
+
40
+ auc = roc_auc_score(y_test, y_proba)
41
+ prec = precision_score(y_test, y_pred)
42
+ rec = recall_score(y_test, y_pred)
43
+ f1 = f1_score(y_test, y_pred)
44
+ cm = confusion_matrix(y_test, y_pred)
45
+
46
+ return f"""
47
+ <b>AUC:</b> {auc}<br>
48
+ <b>Precisão:</b> {prec}<br>
49
+ <b>Recall:</b> {rec}<br>
50
+ <b>F1:</b> {f1}<br>
51
+ <b>Matriz de confusão:</b><br>{cm}
52
+ """
53
+
54
+ with gr.Blocks() as demo:
55
+ gr.Markdown("# 📊 Dashboard da Tarefa 4 — Bônus")
56
+ file = gr.File(label="Envie seu CSV")
57
+
58
+ show_head = gr.Button("Mostrar primeiras linhas")
59
+ head_output = gr.HTML()
60
+
61
+ with gr.Row():
62
+ target = gr.Textbox(label="Variável alvo (Y)")
63
+ features = gr.Textbox(label="Features (X) separadas por vírgula")
64
+
65
+ model_choice = gr.Dropdown(["Regressão Logística", "Random Forest"], label="Modelo")
66
+
67
+ train_button = gr.Button("Treinar Modelo")
68
+ train_output = gr.HTML()
69
+
70
+ show_head.click(process_file, inputs=file, outputs=head_output)
71
+ train_button.click(train_model, inputs=[file, target, features, model_choice], outputs=train_output)
72
+
73
+ demo.launch()
readme.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📊 Dashboard Interativo – Tarefa 4 (SIEP)
2
+ Este é o dashboard para o bônus de inovação, permitindo:
3
+
4
+ - Upload da base
5
+ - Seleção de variáveis
6
+ - Treinamento de modelo (Logística ou Random Forest)
7
+ - Exibição de métricas (AUC, Precisão, Recall, F1)
8
+ - Matriz de confusão
9
+
10
+ Criado com **Gradio**, totalmente compatível com Hugging Face Spaces.
requisitos.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ imbalanced-learn
6
+ matplotlib
7
+