File size: 4,724 Bytes
a408d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Analyse Exploratoire — Dakar Power Prediction\n",
    "\n",
    "Exploration du dataset `synthetic_data_v2.csv` : distributions, corrélations, patterns temporels."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "sns.set_theme(style='whitegrid')\n",
    "plt.rcParams['figure.figsize'] = (10, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('../data/synthetic/synthetic_data_v2.csv', parse_dates=['date_heure'])\n",
    "\n",
    "print('Shape   :', df.shape)\n",
    "print('\\ndtypes :')\n",
    "print(df.dtypes)\n",
    "print('\\nMissing :')\n",
    "print(df.isnull().sum())\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "taux = df.groupby('quartier')['coupure'].mean().sort_values(ascending=False) * 100\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 5))\n",
    "colors = ['#dc3545' if t >= 10 else '#ffc107' if t >= 7 else '#28a745' for t in taux]\n",
    "taux.plot.bar(ax=ax, color=colors, edgecolor='white')\n",
    "ax.set_title('Taux de Coupure par Quartier (%)')\n",
    "ax.set_xlabel('Quartier')\n",
    "ax.set_ylabel('Taux (%)')\n",
    "ax.tick_params(axis='x', rotation=30)\n",
    "for i, v in enumerate(taux):\n",
    "    ax.text(i, v + 0.1, f'{v:.1f}%', ha='center', fontsize=9)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "num_cols = ['temp_celsius', 'humidite_percent', 'vitesse_vent', 'conso_megawatt',\n",
    "            'heure', 'jour_semaine', 'mois', 'saison', 'is_peak_hour', 'coupure']\n",
    "\n",
    "corr = df[num_cols].corr()\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 8))\n",
    "sns.heatmap(\n",
    "    corr, annot=True, fmt='.2f', cmap='coolwarm',\n",
    "    center=0, ax=ax, linewidths=0.5\n",
    ")\n",
    "ax.set_title('Heatmap de Corrélation des Features')\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "by_hour = df.groupby('heure')['coupure'].mean() * 100\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 4))\n",
    "ax.plot(by_hour.index, by_hour.values, marker='o', color='steelblue', linewidth=2)\n",
    "ax.fill_between(by_hour.index, by_hour.values, alpha=0.15, color='steelblue')\n",
    "ax.axvspan(18, 22, alpha=0.12, color='red', label='Heures de pointe (18-22h)')\n",
    "ax.set_title('Taux de Coupure par Heure de la Journée')\n",
    "ax.set_xlabel('Heure')\n",
    "ax.set_ylabel('Taux (%)')\n",
    "ax.set_xticks(range(0, 24))\n",
    "ax.legend()\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "by_month = df.groupby('mois')['coupure'].mean() * 100\n",
    "month_labels = ['Jan','Fév','Mar','Avr','Mai','Juin','Juil','Aoû','Sep','Oct','Nov','Déc']\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 4))\n",
    "by_month.plot.bar(ax=ax, color='coral', edgecolor='white')\n",
    "ax.set_title('Taux de Coupure par Mois')\n",
    "ax.set_xlabel('Mois')\n",
    "ax.set_ylabel('Taux (%)')\n",
    "ax.set_xticklabels(month_labels, rotation=0)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['coupure_label'] = df['coupure'].map({0: 'Pas de coupure', 1: 'Coupure'})\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(8, 5))\n",
    "sns.boxplot(\n",
    "    data=df, x='coupure_label', y='temp_celsius',\n",
    "    palette={'Pas de coupure': '#28a745', 'Coupure': '#dc3545'},\n",
    "    ax=ax\n",
    ")\n",
    "ax.set_title('Distribution de la Température selon la Coupure')\n",
    "ax.set_xlabel('')\n",
    "ax.set_ylabel('Température (°C)')\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n",
    "df.drop(columns=['coupure_label'], inplace=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}