-
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
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c1bfc74
add datasets
xadupre f5dd663
fix pretraitement image
xadupre 6363be9
update
xadupre 7e22ead
fix
xadupre 33ef43a
fix
xadupre 323ab00
se3
xadupre 9e6e291
plan
xadupre f03262d
fix
xadupre d2aa378
fix
xadupre 0b65aac
fix
xadupre 04b26fc
Update _doc/examples/ml/plot_template_data.py
sdpython 472a825
Update _doc/examples/ml/plot_template_data.py
sdpython 3f9807d
Update _doc/examples/ml/plot_template_data.py
sdpython 0de836b
Update _doc/examples/ml/plot_template_data.py
sdpython d6b559e
Update _doc/examples/ml/plot_template_data.py
sdpython 355cf1f
Update _doc/examples/ml/plot_template_data.py
sdpython ed44d5d
Fix four bugs in plot_template_data.py causing compute_oracle and pip…
Copilot 4a0ec49
fix
xadupre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,3 +78,4 @@ _doc/c_data/*.txt | |
| _doc/c_data/*.xlsx | ||
| _doc/c_data/*.zip | ||
| _doc/c_data/*.dbf | ||
| _notebooks/*qwen* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """ | ||
| 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)}" | ||
| subset = df[[*keys, cible]] | ||
| mask = subset.duplicated(subset=keys, keep=False) | ||
| return subset[~mask].reset_index(drop=True), cible | ||
|
|
||
|
|
||
| def compute_oracle(table, cible): | ||
| vars = [c for c in table.columns if c != cible] | ||
| f2025 = table["Session"] == 2025 | ||
| f2024 = table["Session"] == 2024 | ||
| ftwo = table[f2025 | f2024] | ||
| piv = ( | ||
| pandas.pivot_table( | ||
| ftwo, | ||
| index=[c for c in vars if c != "Session"], | ||
| columns="Session", | ||
| values=cible, | ||
| ) | ||
| .dropna(axis=0) | ||
| .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." | ||
| ) | ||
| return mean_absolute_error(piv[2025], piv[2024]) | ||
|
|
||
|
|
||
| def split_train_test(table, cible): | ||
| X, y = table.drop(cible, axis=1), table[cible] | ||
|
|
||
| train_test = X["Session"] < 2025 | ||
|
|
||
| drop = ["Session", "Code UAI de l'établissement", "Établissement"] | ||
|
|
||
| train_X = X[train_test].drop(drop, axis=1) | ||
| train_y = y[train_test] | ||
| test_X = X[~train_test].drop(drop, axis=1) | ||
| test_y = y[~train_test] | ||
| return train_X, test_X, train_y, test_y | ||
|
|
||
|
|
||
| def make_pipeline(table, cible): | ||
| vars = [c for c in table.columns if c != cible] | ||
| num_cols = ["Capacité de l’établissement par formation"] | ||
| 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), | ||
| ), | ||
| ("regressor", HistGradientBoostingRegressor()), | ||
| ] | ||
| ) | ||
| return model | ||
|
|
||
|
|
||
| data = get_data() | ||
| table, cible = select_variables_and_clean(data) | ||
| # oracle = compute_oracle(table, cible) | ||
| # print(f"oracle : {oracle}") | ||
|
|
||
| # train_X, test_X, train_y, test_y = split_train_test(table, cible) | ||
| # model = make_pipeline(table, cible) | ||
| # model.fit(train_X, train_y) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.