Spaces:
Sleeping
Sleeping
Upload superkart_sales_forecast.pkl
Browse files- superkart_sales_forecast.pkl +3 -54
superkart_sales_forecast.pkl
CHANGED
|
@@ -1,54 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
import pandas as pd
|
| 5 |
-
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor # or whatever models you trained
|
| 6 |
-
|
| 7 |
-
# Replace with your actual evaluation function
|
| 8 |
-
def evaluate_model(y_true, y_pred):
|
| 9 |
-
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
|
| 10 |
-
return {
|
| 11 |
-
"RMSE": mean_squared_error(y_true, y_pred, squared=False),
|
| 12 |
-
"MAE": mean_absolute_error(y_true, y_pred),
|
| 13 |
-
"R2": r2_score(y_true, y_pred)
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
# Assume rf_best_model and gb_best_model are already trained
|
| 17 |
-
# Also assume we have performance_df with RMSE values
|
| 18 |
-
|
| 19 |
-
# Example: Simulate performance_df (you should use the real one)
|
| 20 |
-
# import pandas as pd
|
| 21 |
-
# performance_df = pd.DataFrame({
|
| 22 |
-
# "RMSE": {
|
| 23 |
-
# "Random Forest (Tuned)": 113.52,
|
| 24 |
-
# "Gradient Boosting (Tuned)": 119.40
|
| 25 |
-
# }
|
| 26 |
-
# })
|
| 27 |
-
|
| 28 |
-
# -----------------------------
|
| 29 |
-
# Select Final Model Based on RMSE
|
| 30 |
-
# -----------------------------
|
| 31 |
-
best_model = rf_best_model if performance_df["RMSE"].idxmin() == "Random Forest (Tuned)" else gb_best_model
|
| 32 |
-
|
| 33 |
-
# Predict and evaluate
|
| 34 |
-
final_predictions = best_model.predict(X_test)
|
| 35 |
-
final_metrics = evaluate_model(y_test, final_predictions)
|
| 36 |
-
|
| 37 |
-
print("\nBest Model Selected:", performance_df['RMSE'].idxmin())
|
| 38 |
-
print("Performance on Test Set:", final_metrics)
|
| 39 |
-
|
| 40 |
-
# -----------------------------
|
| 41 |
-
# Serialize the Best Model
|
| 42 |
-
# -----------------------------
|
| 43 |
-
model_filename = "superkart_sales_forecast.pkl"
|
| 44 |
-
joblib.dump(best_model, model_filename)
|
| 45 |
-
print(f"\nModel serialized and saved as: {model_filename}")
|
| 46 |
-
|
| 47 |
-
# -----------------------------
|
| 48 |
-
# Load and Validate the Model
|
| 49 |
-
# -----------------------------
|
| 50 |
-
loaded_model = joblib.load(model_filename)
|
| 51 |
-
loaded_predictions = loaded_model.predict(X_test)
|
| 52 |
-
loaded_metrics = evaluate_model(y_test, loaded_predictions)
|
| 53 |
-
|
| 54 |
-
print("\nLoaded Model Performance on Test Set:", loaded_metrics)
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d16120bc3a77a32852b7a3bf80ac03499dd44fd38aef8d19ace6c9986c54865e
|
| 3 |
+
size 49992602
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|