{ "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" ] } ] } ] }