Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from sklearn.datasets import load_iris
|
3 |
from sklearn.model_selection import train_test_split
|
4 |
-
from sklearn.linear_model import LogisticRegression
|
5 |
-
from joblib import dump
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return f"Modelo treinado e salvo em: {model_filename}"
|
23 |
|
24 |
-
|
25 |
-
iface = gr.Interface(fn=train_model, inputs=[], outputs=["text"])
|
26 |
-
iface.launch()
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
# Definir o caminho do diret贸rio
|
4 |
+
diretorio = "/mnt/data"
|
5 |
+
|
6 |
+
# Criar o diret贸rio, se ele n茫o existir
|
7 |
+
os.makedirs(diretorio, exist_ok=True)
|
8 |
+
|
9 |
+
# Agora voc锚 pode salvar o modelo nesse diret贸rio
|
10 |
+
from joblib import dump
|
11 |
+
from sklearn.linear_model import LogisticRegression
|
12 |
from sklearn.datasets import load_iris
|
13 |
from sklearn.model_selection import train_test_split
|
|
|
|
|
14 |
|
15 |
+
# Carregar e dividir o dataset
|
16 |
+
data = load_iris()
|
17 |
+
X = data.data
|
18 |
+
y = data.target
|
19 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
|
20 |
|
21 |
+
# Treinar o modelo
|
22 |
+
model = LogisticRegression()
|
23 |
+
model.fit(X_train, y_train)
|
24 |
|
25 |
+
# Salvar o modelo no diret贸rio rec茅m-criado
|
26 |
+
model_filename = os.path.join(diretorio, "model.pkl")
|
27 |
+
dump(model, model_filename)
|
|
|
|
|
28 |
|
29 |
+
print(f"Modelo salvo em: {model_filename}")
|
|
|
|