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