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
83b76a66
Commit
83b76a66
authored
May 09, 2024
by
Joaquin Torres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hyperparam pre orig
parent
e7b89092
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
6 deletions
+6
-6
model_selection/hyperparam_tuning.py
model_selection/hyperparam_tuning.py
+6
-6
model_selection/output/hyperparam.xlsx
model_selection/output/hyperparam.xlsx
+0
-0
model_selection/output/hyperparam_pre_ORIG.xlsx
model_selection/output/hyperparam_pre_ORIG.xlsx
+0
-0
No files found.
model_selection/hyperparam_tuning.py
View file @
83b76a66
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
# --------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
import
numpy
as
np
from
xgboost
import
XGBClassifier
from
xgboost
import
XGBClassifier
from
sklearn.model_selection
import
StratifiedKFold
from
sklearn.model_selection
import
StratifiedKFold
from
sklearn.ensemble
import
RandomForestClassifier
,
BaggingClassifier
,
AdaBoostClassifier
from
sklearn.ensemble
import
RandomForestClassifier
,
BaggingClassifier
,
AdaBoostClassifier
...
@@ -78,7 +79,7 @@ if __name__ == "__main__":
...
@@ -78,7 +79,7 @@ if __name__ == "__main__":
"AB"
:
AdaBoostClassifier
(
algorithm
=
'SAMME'
),
"AB"
:
AdaBoostClassifier
(
algorithm
=
'SAMME'
),
"XGB"
:
XGBClassifier
(),
"XGB"
:
XGBClassifier
(),
"LR"
:
LogisticRegression
(
max_iter
=
1000
),
"LR"
:
LogisticRegression
(
max_iter
=
1000
),
"SVM"
:
SVC
(),
"SVM"
:
SVC
(
max_iter
=
1000
),
"MLP"
:
MLPClassifier
(
max_iter
=
500
)
"MLP"
:
MLPClassifier
(
max_iter
=
500
)
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet')
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet')
}
}
...
@@ -89,7 +90,7 @@ if __name__ == "__main__":
...
@@ -89,7 +90,7 @@ if __name__ == "__main__":
"Bagging"
:
BaggingClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
)),
"Bagging"
:
BaggingClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
)),
"AB"
:
AdaBoostClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
),
algorithm
=
'SAMME'
),
"AB"
:
AdaBoostClassifier
(
estimator
=
DecisionTreeClassifier
(
class_weight
=
'balanced'
),
algorithm
=
'SAMME'
),
"LR"
:
LogisticRegression
(
max_iter
=
1000
,
class_weight
=
'balanced'
),
"LR"
:
LogisticRegression
(
max_iter
=
1000
,
class_weight
=
'balanced'
),
"SVM"
:
SVC
(
class_weight
=
'balanced'
),
"SVM"
:
SVC
(
max_iter
=
1000
,
class_weight
=
'balanced'
),
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet', class_weight='balanced'),
# "ElNet" : LogisticRegression(max_iter=1000, penalty='elasticnet', class_weight='balanced'),
# "XGB": XGBClassifier(), # <-
# "XGB": XGBClassifier(), # <-
# "MLP" : MLPClassifier(max_iter=500) # <-
# "MLP" : MLPClassifier(max_iter=500) # <-
...
@@ -142,7 +143,7 @@ if __name__ == "__main__":
...
@@ -142,7 +143,7 @@ if __name__ == "__main__":
# Store each df as a sheet in an excel file
# Store each df as a sheet in an excel file
sheets_dict
=
{}
sheets_dict
=
{}
for
i
,
group
in
enumerate
([
'pre'
]):
for
i
,
group
in
enumerate
([
'pre'
]):
for
j
,
method
in
enumerate
([
''
,
''
,
'over_'
,
'under_'
]):
for
j
,
method
in
enumerate
([
''
]):
#['', '', 'over_', 'under_']
# Get dataset based on group and method
# Get dataset based on group and method
X
=
data_dic
[
'X_train_'
+
method
+
group
]
X
=
data_dic
[
'X_train_'
+
method
+
group
]
y
=
data_dic
[
'y_train_'
+
method
+
group
]
y
=
data_dic
[
'y_train_'
+
method
+
group
]
...
@@ -154,18 +155,17 @@ if __name__ == "__main__":
...
@@ -154,18 +155,17 @@ if __name__ == "__main__":
print
(
f
"{group}-{method_names[j]}-{model_name}"
)
print
(
f
"{group}-{method_names[j]}-{model_name}"
)
# Find optimal hyperparams for curr model
# Find optimal hyperparams for curr model
params
=
hyperparameters
[
model_name
]
params
=
hyperparameters
[
model_name
]
search
=
RandomizedSearchCV
(
model
,
param_distributions
=
params
,
cv
=
cv
,
n_jobs
=
3
,
scoring
=
'precision'
)
search
=
RandomizedSearchCV
(
model
,
param_distributions
=
params
,
cv
=
cv
,
n_jobs
=
8
,
scoring
=
'precision'
)
search
.
fit
(
X
,
y
)
search
.
fit
(
X
,
y
)
hyperparam_df
.
at
[
model_name
,
'Parameters'
]
=
search
.
best_params_
hyperparam_df
.
at
[
model_name
,
'Parameters'
]
=
search
.
best_params_
hyperparam_df
.
at
[
model_name
,
'Score'
]
=
round
(
search
.
best_score_
,
4
)
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
# Store the DataFrame in the dictionary with a unique key for each sheet
sheet_name
=
f
"{group}_{method_names[j]}"
sheet_name
=
f
"{group}_{method_names[j]}"
sheets_dict
[
sheet_name
]
=
hyperparam_df
sheets_dict
[
sheet_name
]
=
hyperparam_df
# Write results to Excel file
# Write results to Excel file
with
pd
.
ExcelWriter
(
'./output/hyperparam_pre.xlsx'
)
as
writer
:
with
pd
.
ExcelWriter
(
'./output/hyperparam_pre
_ORIG
.xlsx'
)
as
writer
:
for
sheet_name
,
data
in
sheets_dict
.
items
():
for
sheet_name
,
data
in
sheets_dict
.
items
():
data
.
to_excel
(
writer
,
sheet_name
=
sheet_name
)
data
.
to_excel
(
writer
,
sheet_name
=
sheet_name
)
# --------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
...
...
model_selection/output/hyperparam.xlsx
deleted
100644 → 0
View file @
e7b89092
File deleted
model_selection/output/hyperparam_pre_ORIG.xlsx
0 → 100644
View file @
83b76a66
File added
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