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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"provenance": []
|
| 7 |
+
},
|
| 8 |
+
"kernelspec": {
|
| 9 |
+
"name": "python3",
|
| 10 |
+
"display_name": "Python 3"
|
| 11 |
+
},
|
| 12 |
+
"language_info": {
|
| 13 |
+
"name": "python"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"cells": [
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": 5,
|
| 20 |
+
"metadata": {
|
| 21 |
+
"colab": {
|
| 22 |
+
"base_uri": "https://localhost:8080/"
|
| 23 |
+
},
|
| 24 |
+
"id": "-Rf5Cy_o5PR2",
|
| 25 |
+
"outputId": "1c9441b8-3385-49e4-aba1-34c3f4819f92"
|
| 26 |
+
},
|
| 27 |
+
"outputs": [
|
| 28 |
+
{
|
| 29 |
+
"output_type": "stream",
|
| 30 |
+
"name": "stdout",
|
| 31 |
+
"text": [
|
| 32 |
+
"Python analysis complete.\n",
|
| 33 |
+
"Saved:\n",
|
| 34 |
+
"- vehicle_performance_summary.csv\n",
|
| 35 |
+
"- weather_performance_summary.csv\n",
|
| 36 |
+
"- region_performance_summary.csv\n",
|
| 37 |
+
"- delivery_mode_performance_summary.csv\n",
|
| 38 |
+
"- distance_performance_summary.csv\n",
|
| 39 |
+
"- qualitative_insights.csv\n"
|
| 40 |
+
]
|
| 41 |
+
}
|
| 42 |
+
],
|
| 43 |
+
"source": [
|
| 44 |
+
"import pandas as pd\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"# Load synthetic dataset created in datacreation.ipynb\n",
|
| 47 |
+
"synthetic_delivery_data = pd.read_csv(\"synthetic_delivery_data.csv\")\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"# Preview the columns we will use\n",
|
| 50 |
+
"synthetic_delivery_data[\n",
|
| 51 |
+
" [\n",
|
| 52 |
+
" \"vehicle_type\",\n",
|
| 53 |
+
" \"weather_condition\",\n",
|
| 54 |
+
" \"delivery_mode\",\n",
|
| 55 |
+
" \"region\",\n",
|
| 56 |
+
" \"distance_km\",\n",
|
| 57 |
+
" \"distance_category\",\n",
|
| 58 |
+
" \"delay_hours\",\n",
|
| 59 |
+
" \"delay_score\",\n",
|
| 60 |
+
" \"performance_label\"\n",
|
| 61 |
+
" ]\n",
|
| 62 |
+
"].head()\n",
|
| 63 |
+
"\n",
|
| 64 |
+
"# Quantitative analysis: vehicle performance\n",
|
| 65 |
+
"vehicle_performance = (\n",
|
| 66 |
+
" synthetic_delivery_data\n",
|
| 67 |
+
" .groupby(\"vehicle_type\")[[\"delay_hours\", \"delay_score\"]]\n",
|
| 68 |
+
" .mean()\n",
|
| 69 |
+
" .sort_values(by=\"delay_score\", ascending=False)\n",
|
| 70 |
+
")\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"vehicle_performance\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"# Quantitative analysis: weather performance\n",
|
| 75 |
+
"weather_performance = (\n",
|
| 76 |
+
" synthetic_delivery_data\n",
|
| 77 |
+
" .groupby(\"weather_condition\")[[\"delay_hours\", \"delay_score\"]]\n",
|
| 78 |
+
" .mean()\n",
|
| 79 |
+
" .sort_values(by=\"delay_score\", ascending=False)\n",
|
| 80 |
+
")\n",
|
| 81 |
+
"\n",
|
| 82 |
+
"weather_performance\n",
|
| 83 |
+
"\n",
|
| 84 |
+
"# Quantitative analysis: region performance\n",
|
| 85 |
+
"region_performance = (\n",
|
| 86 |
+
" synthetic_delivery_data\n",
|
| 87 |
+
" .groupby(\"region\")[[\"delay_hours\", \"delay_score\"]]\n",
|
| 88 |
+
" .mean()\n",
|
| 89 |
+
" .sort_values(by=\"delay_score\", ascending=False)\n",
|
| 90 |
+
")\n",
|
| 91 |
+
"\n",
|
| 92 |
+
"region_performance\n",
|
| 93 |
+
"\n",
|
| 94 |
+
"# Quantitative analysis: delivery mode performance\n",
|
| 95 |
+
"mode_performance = (\n",
|
| 96 |
+
" synthetic_delivery_data\n",
|
| 97 |
+
" .groupby(\"delivery_mode\")[[\"delay_hours\", \"delay_score\"]]\n",
|
| 98 |
+
" .mean()\n",
|
| 99 |
+
" .sort_values(by=\"delay_score\", ascending=False)\n",
|
| 100 |
+
")\n",
|
| 101 |
+
"\n",
|
| 102 |
+
"mode_performance\n",
|
| 103 |
+
"\n",
|
| 104 |
+
"# Quantitative analysis: distance performance\n",
|
| 105 |
+
"distance_performance = (\n",
|
| 106 |
+
" synthetic_delivery_data\n",
|
| 107 |
+
" .groupby(\"distance_category\")[[\"delay_hours\", \"delay_score\"]]\n",
|
| 108 |
+
" .mean()\n",
|
| 109 |
+
" .sort_values(by=\"delay_score\", ascending=False)\n",
|
| 110 |
+
")\n",
|
| 111 |
+
"\n",
|
| 112 |
+
"distance_performance\n",
|
| 113 |
+
"\n",
|
| 114 |
+
"# Best conditions summary\n",
|
| 115 |
+
"best_conditions_summary = {\n",
|
| 116 |
+
" \"Best vehicle type\": vehicle_performance.index[0],\n",
|
| 117 |
+
" \"Best weather condition\": weather_performance.index[0],\n",
|
| 118 |
+
" \"Best region\": region_performance.index[0],\n",
|
| 119 |
+
" \"Best delivery mode\": mode_performance.index[0],\n",
|
| 120 |
+
" \"Best distance category\": distance_performance.index[0]\n",
|
| 121 |
+
"}\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"best_conditions_summary\n",
|
| 124 |
+
"\n",
|
| 125 |
+
"# Worst conditions summary\n",
|
| 126 |
+
"worst_conditions_summary = {\n",
|
| 127 |
+
" \"Worst vehicle type\": vehicle_performance.index[-1],\n",
|
| 128 |
+
" \"Worst weather condition\": weather_performance.index[-1],\n",
|
| 129 |
+
" \"Worst region\": region_performance.index[-1],\n",
|
| 130 |
+
" \"Worst delivery mode\": mode_performance.index[-1],\n",
|
| 131 |
+
" \"Worst distance category\": distance_performance.index[-1]\n",
|
| 132 |
+
"}\n",
|
| 133 |
+
"\n",
|
| 134 |
+
"worst_conditions_summary\n",
|
| 135 |
+
"\n",
|
| 136 |
+
"# Qualitative analysis\n",
|
| 137 |
+
"qualitative_insights = pd.DataFrame({\n",
|
| 138 |
+
" \"Qualitative Theme\": [\n",
|
| 139 |
+
" \"Weather disruption\",\n",
|
| 140 |
+
" \"Urban congestion\",\n",
|
| 141 |
+
" \"Vehicle suitability\",\n",
|
| 142 |
+
" \"Customer satisfaction\",\n",
|
| 143 |
+
" \"Delivery mode pressure\"\n",
|
| 144 |
+
" ],\n",
|
| 145 |
+
" \"Business Interpretation\": [\n",
|
| 146 |
+
" \"Bad weather can increase delivery time and reduce delivery reliability.\",\n",
|
| 147 |
+
" \"Central regions may create delays because of traffic and route complexity.\",\n",
|
| 148 |
+
" \"Different vehicle types perform better or worse depending on distance, weather, and region.\",\n",
|
| 149 |
+
" \"Late deliveries can reduce customer ratings and damage customer trust.\",\n",
|
| 150 |
+
" \"Express and same-day deliveries create higher operational pressure.\"\n",
|
| 151 |
+
" ],\n",
|
| 152 |
+
" \"Suggested Action\": [\n",
|
| 153 |
+
" \"Use weather-aware route planning and adjust delivery expectations during bad weather.\",\n",
|
| 154 |
+
" \"Allocate flexible and faster vehicles to central areas.\",\n",
|
| 155 |
+
" \"Match vehicle type to delivery distance, package type, and regional conditions.\",\n",
|
| 156 |
+
" \"Prioritize high-risk deliveries before they become delayed.\",\n",
|
| 157 |
+
" \"Use AI-based delay prediction before accepting urgent delivery promises.\"\n",
|
| 158 |
+
" ]\n",
|
| 159 |
+
"})\n",
|
| 160 |
+
"\n",
|
| 161 |
+
"qualitative_insights\n",
|
| 162 |
+
"\n",
|
| 163 |
+
"# Save quantitative analysis files\n",
|
| 164 |
+
"vehicle_performance.to_csv(\"vehicle_performance_summary.csv\")\n",
|
| 165 |
+
"weather_performance.to_csv(\"weather_performance_summary.csv\")\n",
|
| 166 |
+
"region_performance.to_csv(\"region_performance_summary.csv\")\n",
|
| 167 |
+
"mode_performance.to_csv(\"delivery_mode_performance_summary.csv\")\n",
|
| 168 |
+
"distance_performance.to_csv(\"distance_performance_summary.csv\")\n",
|
| 169 |
+
"\n",
|
| 170 |
+
"# Save qualitative analysis file\n",
|
| 171 |
+
"qualitative_insights.to_csv(\"qualitative_insights.csv\", index=False)\n",
|
| 172 |
+
"\n",
|
| 173 |
+
"print(\"Python analysis complete.\")\n",
|
| 174 |
+
"print(\"Saved:\")\n",
|
| 175 |
+
"print(\"- vehicle_performance_summary.csv\")\n",
|
| 176 |
+
"print(\"- weather_performance_summary.csv\")\n",
|
| 177 |
+
"print(\"- region_performance_summary.csv\")\n",
|
| 178 |
+
"print(\"- delivery_mode_performance_summary.csv\")\n",
|
| 179 |
+
"print(\"- distance_performance_summary.csv\")\n",
|
| 180 |
+
"print(\"- qualitative_insights.csv\")"
|
| 181 |
+
]
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"cell_type": "code",
|
| 185 |
+
"source": [
|
| 186 |
+
"import os\n",
|
| 187 |
+
"import matplotlib.pyplot as plt\n",
|
| 188 |
+
"\n",
|
| 189 |
+
"# Create the exact folders many university Hugging Face templates expect\n",
|
| 190 |
+
"os.makedirs(\"artifacts/py/figures\", exist_ok=True)\n",
|
| 191 |
+
"os.makedirs(\"artifacts/py/tables\", exist_ok=True)\n",
|
| 192 |
+
"\n",
|
| 193 |
+
"# Save tables\n",
|
| 194 |
+
"vehicle_performance.to_csv(\"artifacts/py/tables/vehicle_performance_summary.csv\")\n",
|
| 195 |
+
"weather_performance.to_csv(\"artifacts/py/tables/weather_performance_summary.csv\")\n",
|
| 196 |
+
"region_performance.to_csv(\"artifacts/py/tables/region_performance_summary.csv\")\n",
|
| 197 |
+
"mode_performance.to_csv(\"artifacts/py/tables/delivery_mode_performance_summary.csv\")\n",
|
| 198 |
+
"distance_performance.to_csv(\"artifacts/py/tables/distance_performance_summary.csv\")\n",
|
| 199 |
+
"qualitative_insights.to_csv(\"artifacts/py/tables/qualitative_insights.csv\", index=False)\n",
|
| 200 |
+
"\n",
|
| 201 |
+
"# Save charts\n",
|
| 202 |
+
"vehicle_performance[\"delay_score\"].plot(kind=\"bar\", title=\"Average Delay Score by Vehicle Type\")\n",
|
| 203 |
+
"plt.ylabel(\"Average Delay Score\")\n",
|
| 204 |
+
"plt.tight_layout()\n",
|
| 205 |
+
"plt.savefig(\"artifacts/py/figures/vehicle_performance_chart.png\")\n",
|
| 206 |
+
"plt.close()\n",
|
| 207 |
+
"\n",
|
| 208 |
+
"weather_performance[\"delay_score\"].plot(kind=\"bar\", title=\"Average Delay Score by Weather Condition\")\n",
|
| 209 |
+
"plt.ylabel(\"Average Delay Score\")\n",
|
| 210 |
+
"plt.tight_layout()\n",
|
| 211 |
+
"plt.savefig(\"artifacts/py/figures/weather_performance_chart.png\")\n",
|
| 212 |
+
"plt.close()\n",
|
| 213 |
+
"\n",
|
| 214 |
+
"region_performance[\"delay_score\"].plot(kind=\"bar\", title=\"Average Delay Score by Region\")\n",
|
| 215 |
+
"plt.ylabel(\"Average Delay Score\")\n",
|
| 216 |
+
"plt.tight_layout()\n",
|
| 217 |
+
"plt.savefig(\"artifacts/py/figures/region_performance_chart.png\")\n",
|
| 218 |
+
"plt.close()\n",
|
| 219 |
+
"\n",
|
| 220 |
+
"mode_performance[\"delay_score\"].plot(kind=\"bar\", title=\"Average Delay Score by Delivery Mode\")\n",
|
| 221 |
+
"plt.ylabel(\"Average Delay Score\")\n",
|
| 222 |
+
"plt.tight_layout()\n",
|
| 223 |
+
"plt.savefig(\"artifacts/py/figures/delivery_mode_performance_chart.png\")\n",
|
| 224 |
+
"plt.close()\n",
|
| 225 |
+
"\n",
|
| 226 |
+
"distance_performance[\"delay_score\"].plot(kind=\"bar\", title=\"Average Delay Score by Distance Category\")\n",
|
| 227 |
+
"plt.ylabel(\"Average Delay Score\")\n",
|
| 228 |
+
"plt.tight_layout()\n",
|
| 229 |
+
"plt.savefig(\"artifacts/py/figures/distance_performance_chart.png\")\n",
|
| 230 |
+
"plt.close()\n",
|
| 231 |
+
"\n",
|
| 232 |
+
"print(\"Saved outputs for Hugging Face template.\")\n",
|
| 233 |
+
"print(\"Figures saved in: artifacts/py/figures\")\n",
|
| 234 |
+
"print(\"Tables saved in: artifacts/py/tables\")"
|
| 235 |
+
],
|
| 236 |
+
"metadata": {
|
| 237 |
+
"colab": {
|
| 238 |
+
"base_uri": "https://localhost:8080/"
|
| 239 |
+
},
|
| 240 |
+
"id": "3f3Jj1q2_OTo",
|
| 241 |
+
"outputId": "4748d8e9-fb59-4730-a808-a2a1aa196d83"
|
| 242 |
+
},
|
| 243 |
+
"execution_count": 7,
|
| 244 |
+
"outputs": [
|
| 245 |
+
{
|
| 246 |
+
"output_type": "stream",
|
| 247 |
+
"name": "stdout",
|
| 248 |
+
"text": [
|
| 249 |
+
"Saved outputs for Hugging Face template.\n",
|
| 250 |
+
"Figures saved in: artifacts/py/figures\n",
|
| 251 |
+
"Tables saved in: artifacts/py/tables\n"
|
| 252 |
+
]
|
| 253 |
+
}
|
| 254 |
+
]
|
| 255 |
+
}
|
| 256 |
+
]
|
| 257 |
+
}
|