-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
81 lines (63 loc) · 1.75 KB
/
predict.py
File metadata and controls
81 lines (63 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pandas as pd
import joblib
model = joblib.load("congestion_model.pkl")
model_columns = joblib.load("model_columns.pkl")
def predict_risk(input_dict):
df = pd.DataFrame([input_dict])
df = pd.get_dummies(df)
# align with training columns
df = df.reindex(columns=model_columns, fill_value=0)
prob = model.predict_proba(df)[0][1]
return {
"congestion_probability": float(prob),
"risk_level": "HIGH" if prob > 0.6 else "LOW"
}
# =========================
# EXAMPLE INPUT
# =========================
sample_input = {
"portcalls": 120,
"cargo_volume_teu": 50000,
"total_trade_usd": 1000000,
"rolling_avg_calls_28d": 110,
"rolling_avg_container_28d": 48000,
"rolling_avg_trade_28d": 950000,
"weather_forecast_severity": 2,
"cyclone_probability": 0.3,
"wind_speed_kmh": 40,
"wave_height_m": 2,
"rainfall_mm": 25,
"visibility_km": 5,
"historical_disruption_rate": 0.2,
"days_since_last_disruption": 10,
"active_disruptions_nearby": 1,
"month": 7,
"day_of_week": 3,
"trend_calls": 10,
"trend_cargo": 2000,
"port_name": "Chennai",
"season": "monsoon",
# lag features (last 7 days)
"portcalls_lag1": 115,
"portcalls_lag2": 110,
"portcalls_lag3": 105,
"portcalls_lag4": 100,
"portcalls_lag5": 95,
"portcalls_lag6": 90,
"portcalls_lag7": 85,
"cargo_lag1": 48000,
"cargo_lag2": 47000,
"cargo_lag3": 46000,
"cargo_lag4": 45000,
"cargo_lag5": 44000,
"cargo_lag6": 43000,
"cargo_lag7": 42000,
"rainfall_lag1": 20,
"rainfall_lag2": 15,
"rainfall_lag3": 10,
"rainfall_lag4": 5,
"rainfall_lag5": 0,
"rainfall_lag6": 0,
"rainfall_lag7": 0
}
print(predict_risk(sample_input))