Skip to content

Commit d242257

Browse files
authored
At this point, notebooks should now all be functional ! (#547)
* solve pipeline chapter * feature selection * pandas suite * pandas suite * solve maps * formatting test
1 parent c641de0 commit d242257

5 files changed

Lines changed: 92 additions & 104 deletions

File tree

‎.github/workflows/prod.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ jobs:
147147
- name: Define matrix
148148
id: set-matrix
149149
run: |
150-
echo "::set-output name=matrix::$(find . -type f -name "*.ipynb" ! -name "_*" ! -regex '.*/getting-started/.*' ! -regex '.*/modern-ds/.*' | jq -R -s -c 'split("\n")[:-1]')"
150+
echo "::set-output name=matrix::$(find . -type f -name "*.ipynb" \
151+
! -name "_*" \
152+
! -regex '.*/getting-started/.*' \
153+
! -regex '.*/modern-ds/.*' \
154+
! -regex '.*/manipulation/04a_webscraping_TP.*' \
155+
! -regex '.*/NLP/05_exo_supp.*' \
156+
| jq -R -s -c 'split("\n")[:-1]')"
151157
152158
check:
153159
needs: define-matrix

‎content/manipulation/02_pandas_suite/_exo5_preliminary.qmd‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2+
::: {.content-visible when-profile="fr"}
3+
Pour être sûr d'être en mesure d'effectuer le prochain exercice, voici le dataframe nécessaire pour celui-ci
4+
:::
5+
6+
::: {.content-visible when-profile="en"}
7+
To ensure you are able to complete the next exercise, here is the dataframe required for it.
8+
:::
9+
10+
11+
```{python}
12+
#| echo: true
13+
emissions['emissions'] = emissions.sum(axis = 1, numeric_only = True)
14+
15+
emissions_merged = (
16+
emissions.reset_index()
17+
.merge(filosofi, left_on = "INSEE commune", right_on = "CODGEO")
18+
)
19+
emissions_merged['empreinte'] = emissions_merged['emissions']/emissions_merged['NBPERSMENFISC16']
20+
emissions_merged['empreinte'] = emissions_merged['empreinte'].astype(float)
21+
```
22+
123
```{python}
224
#| echo: true
325
emissions_table = (

‎content/modelisation/4_featureselection.qmd‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ d'optimisation difficilement tractable.
493493
from sklearn.impute import SimpleImputer
494494
from sklearn.preprocessing import StandardScaler
495495
496+
df2.replace([np.inf, -np.inf], np.nan, inplace=True)
497+
X_train, X_test, y_train, y_test = train_test_split(
498+
df2.drop(["per_gop"], axis = 1),
499+
100*df2[['per_gop']], test_size=0.2, random_state=0
500+
)
501+
502+
numerical_features = X_train.select_dtypes(include='number').columns.tolist()
503+
categorical_features = X_train.select_dtypes(exclude='number').columns.tolist()
504+
496505
numeric_pipeline = Pipeline(steps=[
497506
('impute', SimpleImputer(strategy='mean')),
498507
('scale', StandardScaler())
@@ -574,6 +583,8 @@ prédire le résultat Républicain :
574583
#| output: false
575584
from sklearn.linear_model import LassoCV
576585
586+
my_alphas = np.array([0.001,0.01,0.02,0.025,0.05,0.1,0.25,0.5,0.8,1.0])
587+
577588
lcv = (
578589
LassoCV(
579590
alphas=my_alphas,
@@ -599,6 +610,24 @@ utilisé pour faire tourner un nouveau _pipeline_:
599610
```{python}
600611
#| echo: true
601612
#| output: false
613+
from sklearn.compose import make_column_transformer, ColumnTransformer
614+
from sklearn.preprocessing import OneHotEncoder, StandardScaler
615+
616+
numeric_pipeline = Pipeline(steps=[
617+
('impute', SimpleImputer(strategy='mean')),
618+
('scale', StandardScaler())
619+
])
620+
621+
categorical_pipeline = Pipeline(steps=[
622+
('impute', SimpleImputer(strategy='most_frequent')),
623+
('one-hot', OneHotEncoder(handle_unknown='ignore', sparse_output=False))
624+
])
625+
626+
preprocessor = ColumnTransformer(transformers=[
627+
('number', numeric_pipeline, numerical_features),
628+
('category', categorical_pipeline, categorical_features)
629+
])
630+
602631
model = Lasso(
603632
fit_intercept=False,
604633
alpha = lcv.alpha_
@@ -609,7 +638,6 @@ lasso_pipeline = Pipeline(steps=[
609638
('model', model)
610639
])
611640
612-
613641
lasso_optimal = lasso_pipeline.fit(X_train,y_train)
614642
615643
features_selec2 = extract_features_selected(lasso_optimal)

‎content/modelisation/6_pipeline.qmd‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ de celles-ci :
853853
#| label: estim-model-paris
854854
#| echo: true
855855
from sklearn.ensemble import GradientBoostingRegressor
856+
from sklearn.impute import SimpleImputer
857+
from sklearn.preprocessing import StandardScaler, OneHotEncoder
858+
from sklearn.pipeline import make_pipeline, Pipeline
859+
from sklearn.compose import make_column_transformer
860+
from sklearn.model_selection import train_test_split
861+
856862
857863
mutations_paris = mutations.drop(
858864
colonnes_surface.tolist() + ["Date mutation", "lprix"], # ajouter "confinement" si données 2020

0 commit comments

Comments
 (0)