Spaces:
No application file
No application file
Upload 3 files
Browse files- data_loader.py +14 -0
- tools.py +35 -0
- train_model.py +18 -0
data_loader.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
def load_data():
|
| 4 |
+
df_m = pd.read_csv("data/Hauler_Machine_IPR.csv")
|
| 5 |
+
df_p = pd.read_csv("data/Hauler_People_IPR.csv")
|
| 6 |
+
df_w = pd.read_csv("data/Hauler_Weather_IPR.csv")
|
| 7 |
+
|
| 8 |
+
# Gabungkan berdasarkan tanggal
|
| 9 |
+
df = df_m.merge(df_p, on="date", how="inner")
|
| 10 |
+
df = df.merge(df_w, on="date", how="inner")
|
| 11 |
+
|
| 12 |
+
# Pastikan kolom sesuai
|
| 13 |
+
df["cuaca_bin"] = df["cuaca"].map({"cerah": 0, "hujan": 1})
|
| 14 |
+
return df
|
tools.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
model = joblib.load("model_pty.pkl")
|
| 5 |
+
|
| 6 |
+
def predict_pty(pa, wicope, backlog, cuaca, resign, bad_ethic, incompetent):
|
| 7 |
+
data = pd.DataFrame([{
|
| 8 |
+
"PA": pa,
|
| 9 |
+
"WICOPE": wicope,
|
| 10 |
+
"backlog": backlog,
|
| 11 |
+
"cuaca_bin": 1 if cuaca == "hujan" else 0,
|
| 12 |
+
"resign": resign,
|
| 13 |
+
"bad_ethic": bad_ethic,
|
| 14 |
+
"incompetent": incompetent
|
| 15 |
+
}])
|
| 16 |
+
result = model.predict(data)[0]
|
| 17 |
+
return int(result)
|
| 18 |
+
|
| 19 |
+
def analyze_causes(pa, wicope, backlog, cuaca, resign, bad_ethic, incompetent):
|
| 20 |
+
alasan = []
|
| 21 |
+
if pa < 90: alasan.append("PA rendah (<90%)")
|
| 22 |
+
if wicope < 90: alasan.append("WICOPE <90%")
|
| 23 |
+
if backlog > 30: alasan.append("Backlog terlalu banyak")
|
| 24 |
+
if cuaca == "hujan": alasan.append("Cuaca buruk")
|
| 25 |
+
if resign > 1: alasan.append("Tingkat resign tinggi")
|
| 26 |
+
if bad_ethic > 0: alasan.append("Ada perilaku buruk")
|
| 27 |
+
if incompetent > 0: alasan.append("SDM tidak kompeten")
|
| 28 |
+
return alasan
|
| 29 |
+
|
| 30 |
+
def give_recommendation(backlog, pa, resign):
|
| 31 |
+
rekom = []
|
| 32 |
+
if backlog > 30: rekom.append("Percepat eksekusi backlog")
|
| 33 |
+
if pa < 90: rekom.append("Tingkatkan ketersediaan alat")
|
| 34 |
+
if resign > 1: rekom.append("Cegah resign dengan retensi")
|
| 35 |
+
return rekom
|
train_model.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.ensemble import RandomForestRegressor
|
| 3 |
+
import joblib
|
| 4 |
+
from data_loader import load_data
|
| 5 |
+
|
| 6 |
+
df = load_data()
|
| 7 |
+
|
| 8 |
+
features = ['PA', 'WICOPE', 'backlog', 'cuaca_bin', 'resign', 'bad_ethic', 'incompetent']
|
| 9 |
+
target = 'PTY'
|
| 10 |
+
|
| 11 |
+
X = df[features]
|
| 12 |
+
y = df[target]
|
| 13 |
+
|
| 14 |
+
model = RandomForestRegressor()
|
| 15 |
+
model.fit(X, y)
|
| 16 |
+
|
| 17 |
+
joblib.dump(model, "model_pty.pkl")
|
| 18 |
+
print("✅ Model trained and saved as model_pty.pkl")
|