Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,14 +8,16 @@ model = joblib.load("best_model.pkl")
|
|
| 8 |
le_operation_type = joblib.load("le_operation_type.pkl")
|
| 9 |
le_operator_id = joblib.load("le_operator_id.pkl")
|
| 10 |
|
| 11 |
-
def predict_end_date(start_date, quantity,
|
| 12 |
-
# Convert
|
| 13 |
quantity = float(quantity)
|
| 14 |
-
operation_code = int(operation_code)
|
| 15 |
-
operator_code = int(operator_code)
|
| 16 |
day_of_week = int(day_of_week)
|
| 17 |
|
| 18 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
quantity_log = np.log1p(quantity)
|
| 20 |
quantity_log_squared = quantity_log ** 2
|
| 21 |
quantity_log_cubed = quantity_log ** 3
|
|
@@ -24,7 +26,6 @@ def predict_end_date(start_date, quantity, operation_code, operator_code, day_of
|
|
| 24 |
quantity_operator_interaction_squared = quantity_operator_interaction ** 2
|
| 25 |
operation_operator_interaction = operation_code * operator_code
|
| 26 |
|
| 27 |
-
# Match the model's training feature order
|
| 28 |
X = pd.DataFrame([[
|
| 29 |
quantity_log,
|
| 30 |
quantity_log_squared,
|
|
@@ -49,10 +50,9 @@ def predict_end_date(start_date, quantity, operation_code, operator_code, day_of
|
|
| 49 |
'DayOfWeek'
|
| 50 |
])
|
| 51 |
|
| 52 |
-
# Predict
|
| 53 |
pred_days = model.predict(X)[0]
|
| 54 |
|
| 55 |
-
# Convert to date
|
| 56 |
from datetime import datetime, timedelta
|
| 57 |
start_dt = datetime.strptime(start_date, "%d-%m-%Y")
|
| 58 |
end_dt = start_dt + timedelta(days=pred_days)
|
|
|
|
| 8 |
le_operation_type = joblib.load("le_operation_type.pkl")
|
| 9 |
le_operator_id = joblib.load("le_operator_id.pkl")
|
| 10 |
|
| 11 |
+
def predict_end_date(start_date, quantity, operation_type, operator_id, day_of_week):
|
| 12 |
+
# Convert input types
|
| 13 |
quantity = float(quantity)
|
|
|
|
|
|
|
| 14 |
day_of_week = int(day_of_week)
|
| 15 |
|
| 16 |
+
# Use label encoders to convert strings to codes
|
| 17 |
+
operation_code = le_op.transform([operation_type])[0]
|
| 18 |
+
operator_code = le_opr.transform([operator_id])[0]
|
| 19 |
+
|
| 20 |
+
# Feature engineering
|
| 21 |
quantity_log = np.log1p(quantity)
|
| 22 |
quantity_log_squared = quantity_log ** 2
|
| 23 |
quantity_log_cubed = quantity_log ** 3
|
|
|
|
| 26 |
quantity_operator_interaction_squared = quantity_operator_interaction ** 2
|
| 27 |
operation_operator_interaction = operation_code * operator_code
|
| 28 |
|
|
|
|
| 29 |
X = pd.DataFrame([[
|
| 30 |
quantity_log,
|
| 31 |
quantity_log_squared,
|
|
|
|
| 50 |
'DayOfWeek'
|
| 51 |
])
|
| 52 |
|
|
|
|
| 53 |
pred_days = model.predict(X)[0]
|
| 54 |
|
| 55 |
+
# Convert predicted days to readable date + time
|
| 56 |
from datetime import datetime, timedelta
|
| 57 |
start_dt = datetime.strptime(start_date, "%d-%m-%Y")
|
| 58 |
end_dt = start_dt + timedelta(days=pred_days)
|