joannyvit commited on
Commit
89c29b0
·
verified ·
1 Parent(s): 76e48cf

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -73
app.py DELETED
@@ -1,73 +0,0 @@
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()