Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
C
covid_analysis
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
COMPARA
covid_analysis
Commits
e7b89092
Commit
e7b89092
authored
May 09, 2024
by
Joaquin Torres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
preparing for pre tuning
parent
c556b024
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
model_selection/hyperparam_tuning.py
model_selection/hyperparam_tuning.py
+6
-4
No files found.
model_selection/hyperparam_tuning.py
View file @
e7b89092
...
...
@@ -20,6 +20,7 @@ from sklearn.linear_model import LogisticRegression
from
sklearn.tree
import
DecisionTreeClassifier
from
scipy.stats
import
randint
,
uniform
from
sklearn.model_selection
import
RandomizedSearchCV
import
os
# --------------------------------------------------------------------------------------------------------
# Function to read training datasets
...
...
@@ -77,7 +78,7 @@ if __name__ == "__main__":
"AB"
:
AdaBoostClassifier
(
algorithm
=
'SAMME'
),
"XGB"
:
XGBClassifier
(),
"LR"
:
LogisticRegression
(
max_iter
=
1000
),
"SVM"
:
SVC
(
probability
=
True
),
"SVM"
:
SVC
(),
"MLP"
:
MLPClassifier
(
max_iter
=
500
)
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet')
}
...
...
@@ -88,7 +89,7 @@ if __name__ == "__main__":
"Bagging"
:
BaggingClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
)),
"AB"
:
AdaBoostClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
),
algorithm
=
'SAMME'
),
"LR"
:
LogisticRegression
(
max_iter
=
1000
,
class_weight
=
'balanced'
),
"SVM"
:
SVC
(
probability
=
True
,
class_weight
=
'balanced'
),
"SVM"
:
SVC
(
class_weight
=
'balanced'
),
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet', class_weight='balanced'),
# "XGB": XGBClassifier(), # <-
# "MLP" : MLPClassifier(max_iter=500) # <-
...
...
@@ -150,20 +151,21 @@ if __name__ == "__main__":
# Save results: params and best score for each of the mdodels of this method and group
hyperparam_df
=
pd
.
DataFrame
(
index
=
list
(
models
.
keys
()),
columns
=
[
'Parameters'
,
'Score'
])
for
model_name
,
model
in
models
.
items
():
print
(
f
"{group}-{method
}-{model_name}
\n\n
"
)
print
(
f
"{group}-{method
_names[j]}-{model_name}
"
)
# Find optimal hyperparams for curr model
params
=
hyperparameters
[
model_name
]
search
=
RandomizedSearchCV
(
model
,
param_distributions
=
params
,
cv
=
cv
,
n_jobs
=
3
,
scoring
=
'precision'
)
search
.
fit
(
X
,
y
)
hyperparam_df
.
at
[
model_name
,
'Parameters'
]
=
search
.
best_params_
hyperparam_df
.
at
[
model_name
,
'Score'
]
=
round
(
search
.
best_score_
,
4
)
os
.
system
(
'clear'
)
# Store the DataFrame in the dictionary with a unique key for each sheet
sheet_name
=
f
"{group}_{method_names[j]}"
sheets_dict
[
sheet_name
]
=
hyperparam_df
# Write results to Excel file
with
pd
.
ExcelWriter
(
'./output/hyperparam.xlsx'
)
as
writer
:
with
pd
.
ExcelWriter
(
'./output/hyperparam
_pre
.xlsx'
)
as
writer
:
for
sheet_name
,
data
in
sheets_dict
.
items
():
data
.
to_excel
(
writer
,
sheet_name
=
sheet_name
)
# --------------------------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment