Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BigData
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Majorczyk
BigData
Commits
9e422955
You need to sign in or sign up before continuing.
Commit
9e422955
authored
4 months ago
by
Mohamed Sebabti
Browse files
Options
Downloads
Patches
Plain Diff
grid search rn
parent
b2365d4c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ml_rn.py
+25
-11
25 additions, 11 deletions
ml_rn.py
with
25 additions
and
11 deletions
ml_rn.py
+
25
−
11
View file @
9e422955
...
@@ -28,26 +28,40 @@ def train_mlp(df):
...
@@ -28,26 +28,40 @@ def train_mlp(df):
# 2. Séparation train/test
# 2. Séparation train/test
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.2
,
random_state
=
42
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.2
,
random_state
=
42
)
# 3. Normalisation des features
(obligatoire pour MLP)
# 3. Normalisation des features
scaler
=
StandardScaler
()
scaler
=
StandardScaler
()
X_train_scaled
=
scaler
.
fit_transform
(
X_train
)
X_train_scaled
=
scaler
.
fit_transform
(
X_train
)
X_test_scaled
=
scaler
.
transform
(
X_test
)
X_test_scaled
=
scaler
.
transform
(
X_test
)
# 4. Définition et entraînement du modèle MLP
# 4. Définition des hyperparamètres à tester
mlp
=
MLPRegressor
(
hidden_layer_sizes
=
(
100
,
50
),
activation
=
'
relu
'
,
solver
=
'
adam
'
,
max_iter
=
500
,
random_state
=
42
)
param_grid
=
{
mlp
.
fit
(
X_train_scaled
,
y_train
)
'
hidden_layer_sizes
'
:
[(
50
,),
(
100
,),
(
100
,
50
),
(
100
,
100
)],
'
activation
'
:
[
'
relu
'
,
'
tanh
'
],
'
solver
'
:
[
'
adam
'
,
'
sgd
'
],
'
learning_rate_init
'
:
[
0.001
,
0.01
,
0.1
],
'
max_iter
'
:
[
500
]
}
# 5. Prédictions
# 5. Recherche des meilleurs hyperparamètres avec GridSearchCV
y_pred
=
mlp
.
predict
(
X_test_scaled
)
mlp
=
MLPRegressor
(
random_state
=
42
)
grid_search
=
GridSearchCV
(
mlp
,
param_grid
,
cv
=
3
,
scoring
=
'
r2
'
,
n_jobs
=-
1
,
verbose
=
2
)
grid_search
.
fit
(
X_train_scaled
,
y_train
)
# 6. Évaluation du modèle
# 6. Affichage des meilleurs paramètres
print
(
"
Meilleurs paramètres :
"
,
grid_search
.
best_params_
)
# 7. Prédictions avec le meilleur modèle
best_mlp
=
grid_search
.
best_estimator_
y_pred
=
best_mlp
.
predict
(
X_test_scaled
)
# 8. Évaluation du modèle
mae
=
mean_absolute_error
(
y_test
,
y_pred
)
mae
=
mean_absolute_error
(
y_test
,
y_pred
)
rmse
=
np
.
sqrt
(
mean_squared_error
(
y_test
,
y_pred
))
rmse
=
np
.
sqrt
(
mean_squared_error
(
y_test
,
y_pred
))
r2
=
r2_score
(
y_test
,
y_pred
)
r2
=
r2_score
(
y_test
,
y_pred
)
print
(
f
"
📊 MLPRegressor - MAE:
{
mae
:
.
2
f
}
, RMSE:
{
rmse
:
.
2
f
}
, R²:
{
r2
:
.
3
f
}
"
)
print
(
f
"
📊 MLPRegressor
Optimisé
- MAE:
{
mae
:
.
2
f
}
, RMSE:
{
rmse
:
.
2
f
}
, R²:
{
r2
:
.
3
f
}
"
)
#
7
. Ajout des prédictions au DataFrame original
#
9
. Ajout des prédictions au DataFrame original
df
.
loc
[
X_test
.
index
,
'
pred_mlp
'
]
=
y_pred
df
.
loc
[
X_test
.
index
,
'
pred_mlp
'
]
=
y_pred
print
(
df
.
head
(
40
))
print
(
df
.
head
(
40
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment