Skip to content

Commit a9f784c

Browse files
Create train_model.py
Signed-off-by: Fabiana ⚡️ Campanari <113218619+FabianaCampanari@users.noreply.github.com>
1 parent 62d057d commit a9f784c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Codes/train_model.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import pandas as pd
3+
import pickle
4+
from sklearn.ensemble import RandomForestClassifier
5+
from sklearn.model_selection import train_test_split
6+
from sklearn.metrics import classification_report
7+
8+
dados = {
9+
"temperatura": [40, 42, 45, 50, 55, 60, 65, 70, 80, 85, 90, 48, 52, 67, 73, 88],
10+
"vibracao": [0.3, 0.4, 0.5, 0.7, 0.8, 0.9, 1.2, 1.3, 1.5, 1.7, 1.9, 0.6, 0.75, 1.1, 1.4, 1.8],
11+
"rpm": [900, 950, 1000, 1100, 1150, 1200, 1300, 1400, 1500, 1600, 1700, 1050, 1120, 1280, 1450, 1650],
12+
"falha": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1]
13+
}
14+
15+
df = pd.DataFrame(dados)
16+
df.to_csv("exemplo_dados.csv", index=False)
17+
18+
X = df[["temperatura", "vibracao", "rpm"]]
19+
y = df["falha"]
20+
21+
X_train, X_test, y_train, y_test = train_test_split(
22+
X, y, test_size=0.25, random_state=42
23+
)
24+
25+
modelo = RandomForestClassifier(n_estimators=100, random_state=42)
26+
modelo.fit(X_train, y_train)
27+
28+
preds = modelo.predict(X_test)
29+
print(classification_report(y_test, preds))
30+
31+
with open("modelo_falha_rf.pkl", "wb") as f:
32+
pickle.dump(modelo, f)
33+
34+
print("Modelo salvo como modelo_falha_rf.pkl")
35+
print("Dataset salvo como exemplo_dados.csv")

0 commit comments

Comments
 (0)