{ "cells": [ { "cell_type": "markdown", "id": "1643816d", "metadata": {}, "source": [ "# Etude des notes pour le 2e trimestre" ] }, { "cell_type": "code", "execution_count": 1, "id": "ed2de9a9", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown as md\n", "from IPython.display import display, HTML\n", "import pandas as pd\n", "import numpy as np\n", "import ipywidgets as widgets\n", "from pathlib import Path\n", "from datetime import datetime\n", "from recopytex import flat_df_students, pp_q_scores\n", "from datetime import datetime\n", "from pathlib import Path\n", "\n", "import chart_studio.plotly as py\n", "import plotly.graph_objects as go\n", "import plotly.figure_factory as ff\n", "import plotly.express as px\n", "\n", "from plotly.offline import iplot, init_notebook_mode\n", "init_notebook_mode()" ] }, { "cell_type": "code", "execution_count": 2, "id": "556ebf8b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[PosixPath('230317_DS5.csv'),\n", " PosixPath('220922_DS1.csv'),\n", " PosixPath('230224_DS4.csv'),\n", " PosixPath('221201_DM1.csv'),\n", " PosixPath('230118_DS3.csv'),\n", " PosixPath('221214_DS2.csv')]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "score_files = list(Path(\"./\").glob(\"**/*.csv\"))\n", "score_files" ] }, { "cell_type": "code", "execution_count": 67, "id": "304bd86c", "metadata": {}, "outputs": [], "source": [ "reject = [\"221214_DS2.csv\", \"230317_DS5.csv\"]\n", "dfs = []\n", "for file in score_files:\n", " if file.name not in reject:\n", " score_df = pd.read_csv(file, encoding=\"UTF8\")\n", " flat = flat_df_students(score_df).dropna(subset=[\"Score\"])\n", " pp_q = pp_q_scores(flat)\n", " dfs.append(pp_q)\n", "df = pd.concat(dfs)" ] }, { "cell_type": "code", "execution_count": 6, "id": "4788fc47", "metadata": {}, "outputs": [], "source": [ "df = df.astype(dtype={\n", " \"Nom\": \"str\",\n", " \"Trimestre\": \"int64\",\n", " \"Exercice\": \"str\",\n", " \"Question\": \"str\",\n", " \"Competence\": \"str\",\n", " \"Domaine\": \"str\",\n", " \"Commentaire\": \"str\",\n", " \"Est_nivele\": \"bool\",\n", " \"Bareme\": \"float64\",\n", " \"Eleve\": \"str\",\n", " \"Score\": \"float64\",\n", " \n", "})\n", "df.Date = df.Date.apply(pd.to_datetime)" ] }, { "cell_type": "code", "execution_count": 9, "id": "786f5b8f", "metadata": {}, "outputs": [], "source": [ "T2_df = df[df[\"Trimestre\"] == 2]" ] }, { "cell_type": "markdown", "id": "fc7ea54c", "metadata": {}, "source": [ "## Fonctions" ] }, { "cell_type": "code", "execution_count": 68, "id": "92e292b8", "metadata": {}, "outputs": [], "source": [ "def build_pt(df, diff_col, eleve_col, score_col, aggfunc):\n", " \"\"\" Fait une table pivot de df\n", " \n", " Préparation des données pour les clustering\n", " \"\"\"\n", " pt = pd.pivot_table(df,\n", " index=[eleve_col],\n", " columns=[diff_col],\n", " values=[score_col],\n", " aggfunc=aggfunc,)\n", " pt.dropna(inplace=True)\n", " cols_names = pt.columns.get_level_values(-1)\n", " pt.columns = cols_names\n", " return pt.reset_index(), cols_names" ] }, { "cell_type": "code", "execution_count": 69, "id": "557297b9", "metadata": {}, "outputs": [], "source": [ "def clustering(pt, cols_names, method, method_arg={}):\n", " \"\"\" Applique la méthode de clustering sur pt\"\"\"\n", " clu = method(**method_arg)\n", " clu.fit(pt[cols_names])\n", " return pd.Series(clu.labels_, index=pt.index), clu" ] }, { "cell_type": "code", "execution_count": 89, "id": "356d4e4b", "metadata": {}, "outputs": [], "source": [ "def plot_polar_cluster(pt, clustername, clustering, fields):\n", " groups = pt.groupby([clustername]).agg({\"Eleve\":list})\n", " for i, cluster in enumerate(clustering.cluster_centers_):\n", " fig = go.Figure()\n", " fig.add_trace(go.Scatterpolar(\n", " r = cluster,\n", " theta = fields,\n", " name = i,\n", " fill=\"toself\"\n", " ))\n", " \n", "\n", " for eleve in pt[pt[clustername]==i].iterrows():\n", " fig.add_trace(go.Scatterpolar(\n", " r = eleve[1][fields],\n", " theta = fields,\n", " name=eleve[1][\"Eleve\"], \n", " ))\n", " fig.show()" ] }, { "cell_type": "markdown", "id": "84048230", "metadata": {}, "source": [ "## Classification des élèves\n" ] }, { "cell_type": "code", "execution_count": 10, "id": "52f10a04", "metadata": {}, "outputs": [], "source": [ "from sklearn.cluster import KMeans" ] }, { "cell_type": "code", "execution_count": 11, "id": "18ababdd", "metadata": {}, "outputs": [], "source": [ "T2_df = T2_df.assign(\n", " q_id = lambda x: x['Nom']+ x['Exercice'] + x['Question'] + x['Commentaire']\n", " )" ] }, { "cell_type": "markdown", "id": "0f9ca48e", "metadata": {}, "source": [ "## Sur les domaines" ] }, { "cell_type": "code", "execution_count": 103, "id": "548fcb76", "metadata": {}, "outputs": [], "source": [ "T2_pt_dom, domains = build_pt(T2_df, \n", " diff_col=\"Domaine\", \n", " eleve_col=\"Eleve\", \n", " score_col=\"Normalise\", \n", " aggfunc=[np.mean])" ] }, { "cell_type": "code", "execution_count": 104, "id": "e81e7689", "metadata": {}, "outputs": [], "source": [ "T2_pt_dom[\"affinity_cluster\"], affinity_cluster = clustering(T2_pt_dom, domains, AffinityPropagation)\n", "T2_pt_dom[\"kmeans5_cluster\"], kmeans5_cluster = clustering(T2_pt_dom, domains, KMeans, {'n_clusters':5, 'n_init':\"auto\"})\n", "dom_clusters = {\n", " \"affinity_cluster\": affinity_cluster,\n", " \"kmeans5_cluster\": kmeans5_cluster,\n", "}" ] }, { "cell_type": "code", "execution_count": 105, "id": "56365bca", "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "fill": "toself", "name": "0", "r": [ 0.7404938271604938, 0.5604745370370371, 0.8644444444444445, 0.5182222222222223, 0.7319444444444445, 0.2815555555555556, 0.37 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "BREZUN Ines", "r": [ 0.7772222222222221, 0.7708333333333334, 0.8888888888888888, 0.734, 0.9175, 0.3993333333333333, 0.3333333333333333 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "CALLEWAERT Idaline", "r": [ 0.6666666666666666, 0.43729166666666663, 1, 0.599, 0.75, 0, 0.1111111111111111 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "CHRISTMANN Nathan", "r": [ 0.555, 0.3960416666666667, 0.4444444444444444, 0.2, 0.8325, 0.33399999999999996, 0.1111111111111111 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "DEHIMAT Launy", "r": [ 0.8888888888888888, 0.62625, 1, 0.466, 0.67, 0, 0.22111111111111112 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "GASAN Jéssica", "r": [ 0.8883333333333333, 0.6246875, 0.778888888888889, 0.533, 0.5825, 0.535, 0.8888888888888888 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "KICHENASSAMY Sanjay", "r": [ 0.7777777777777777, 0.6879166666666667, 0.89, 0.333, 0.41750000000000004, 0.2, 0.4444444444444444 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "LETIF Ilef", "r": [ 0.6672222222222222, 0.145625, 1, 0.466, 0.75, 0.5333333333333333, 0.8888888888888888 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "RIZZI Elisa", "r": [ 0.6661111111111111, 0.8341666666666667, 0.7777777777777777, 0.4, 0.835, 0.333, 0.22111111111111112 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" }, { "name": "SOUJOL Damien", "r": [ 0.7772222222222221, 0.5214583333333334, 1, 0.933, 0.8325, 0.1993333333333333, 0.11 ], "theta": [ "Calcul littéral", "Fonctions", "Fractions", "Géométrie", "Information chiffrée", "Probabilité", "Programmation" ], "type": "scatterpolar" } ], "layout": { "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "