-
Notifications
You must be signed in to change notification settings - Fork 1
add datasets - teaching #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Données parcours-sup 2021-2025 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ============================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pandas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from teachpyx.tools.pandas import read_csv_cached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sklearn.metrics import mean_absolute_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sklearn.pipeline import Pipeline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sklearn.compose import ColumnTransformer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sklearn.preprocessing import OneHotEncoder, StandardScaler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sklearn.ensemble import HistGradientBoostingRegressor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # from skrub import TableReport | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_data(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| urls = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2021": "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup_2021/exports/csv?lang=fr&timezone=Europe%2FBerlin&use_labels=true&delimiter=%3B", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2022": "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup_2022/exports/csv?lang=fr&timezone=Europe%2FBerlin&use_labels=true&delimiter=%3B", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2023": "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup_2023/exports/csv?lang=fr&timezone=Europe%2FBerlin&use_labels=true&delimiter=%3B", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2024": "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup_2024/exports/csv?lang=fr&timezone=Europe%2FBerlin&use_labels=true&delimiter=%3B", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "2025": "https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/exports/csv?lang=fr&timezone=Europe%2FBerlin&use_labels=true&delimiter=%3B", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dfs = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for k, url in urls.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"loading {k!r}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dfs[k] = read_csv_cached(url, sep=";") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pandas.concat(dfs.values(), axis=0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def select_variables_and_clean(df): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| keys = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Région de l’établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Session", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Statut de l’établissement de la filière de formation (public, privé…)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Sélectivité", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Code UAI de l'établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Filière de formation détaillée bis", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Filière de formation très agrégée", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Filière de formation.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Académie de l’établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Code départemental de l’établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Commune de l’établissement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Concours communs et banque d'épreuves", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cible = "Effectif total des candidats pour une formation" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| columns = set(df.columns) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert set(keys) & set(columns) == set( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), f"Missing columns {set(keys) - set(keys) & set(columns)} in {sorted(df.columns)}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), f"Missing columns {set(keys) - set(keys) & set(columns)} in {sorted(df.columns)}" | |
| ), f"Missing columns {set(keys) - set(columns)} in {sorted(df.columns)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot why it does not work?
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the question about why dropna fails: The pivot_table operation creates a DataFrame with multi-column index (2024 and 2025 as columns). When there are missing values in either year, dropna(axis=0) would remove those rows. The likely issue is that after removing rows with NaN values, the resulting DataFrame might be empty or nearly empty, causing the mean_absolute_error calculation on line 78 to fail. The pivot table requires matching keys between 2024 and 2025 data, and if many formations only appear in one year, many NaN values would be created. Consider using fillna(0) or only comparing formations that exist in both years by using an inner join approach in the pivot_table.
| # .dropna(axis=0) # fails | |
| .sort_index() | |
| ) | |
| .sort_index() | |
| ) | |
| # Keep only rows where both 2024 and 2025 have non-missing values | |
| piv = piv.dropna(axis=0, how="any") | |
| if piv.empty: | |
| raise ValueError( | |
| "Not enough overlapping data between 2024 and 2025 to compute oracle." | |
| ) |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter name has a typo: 'cuble' should be 'cible' to match the variable name used throughout the codebase and in the function body.
| def split_train_test(table, cuble): | |
| def split_train_test(table, cible): |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both test_X and test_y are incorrectly using the training data filter. Lines 90-91 should use ~train_test instead of train_test to select the test set (Session == 2025), otherwise the test set will be identical to the training set.
| test_X = X[train_test].drop(drop, axis=1) | |
| test_y = y[train_test] | |
| test_X = X[~train_test].drop(drop, axis=1) | |
| test_y = y[~train_test] |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition filters by the literal string "cible" instead of using the parameter variable. This should be c != cible to correctly filter out the target column.
| vars = [c for c in table.columns if c != "cible"] | |
| vars = [c for c in table.columns if c != cible] |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The column "Capacité de l'établissement par formation" is not present in the 'keys' list defined in select_variables_and_clean, and therefore won't exist in the table. This will cause a KeyError when the pipeline attempts to apply StandardScaler to this non-existent column. Either add this column to the keys list in select_variables_and_clean, or use a column that is actually present in the filtered table.
| num_cols = ["Capacité de l’établissement par formation"] | |
| cat_cols = [c for c in vars if c not in num_cols] | |
| model = Pipeline( | |
| [ | |
| ( | |
| "preprocessing", | |
| ColumnTransformer( | |
| [ | |
| ("num", StandardScaler(), num_cols), | |
| ("cats", OneHotEncoder(handle_unknown="ignore"), cat_cols), | |
| ] | |
| ), | |
| # Candidate numeric feature; include it only if it exists in the table to avoid KeyError. | |
| numeric_feature = "Capacité de l’établissement par formation" | |
| num_cols = [numeric_feature] if numeric_feature in table.columns else [] | |
| cat_cols = [c for c in vars if c not in num_cols] | |
| transformers = [] | |
| if num_cols: | |
| transformers.append(("num", StandardScaler(), num_cols)) | |
| if cat_cols: | |
| transformers.append( | |
| ("cats", OneHotEncoder(handle_unknown="ignore"), cat_cols) | |
| ) | |
| model = Pipeline( | |
| [ | |
| ( | |
| "preprocessing", | |
| ColumnTransformer(transformers), |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the '# coding: utf-8' header that is present in all other example files in the _doc/examples directory. This header is particularly important for this file since it contains French text with special characters.