From 1436557287df0978a0d297f37ac457f317c35fb0 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Mon, 23 May 2022 00:31:02 +0100 Subject: [PATCH] saving work and wrapping up from the weekend --- UQ_FS_eg.py | 2 +- UQ_LR_FS_p2.py | 21 ++++++++++----------- uq_ml_models/UQ_LR_FS2.py | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/UQ_FS_eg.py b/UQ_FS_eg.py index 49ae5c9..5167729 100644 --- a/UQ_FS_eg.py +++ b/UQ_FS_eg.py @@ -66,7 +66,7 @@ print('\nbest model with feature selection:', fs_bmod) pipe = Pipeline([ ('pre', MinMaxScaler()) - ('selector', RFECV(LogisticRegression(**rs), cv = skf_cv, scoring = 'matthews_corrcoef')) + , ('selector', RFECV(LogisticRegression(**rs), cv = skf_cv, scoring = 'matthews_corrcoef')) , ('classifier', LogisticRegression(**rs))]) search_space = [{'selector__min_features_to_select': [1,2]}, diff --git a/UQ_LR_FS_p2.py b/UQ_LR_FS_p2.py index fb5432c..1a8f7c3 100644 --- a/UQ_LR_FS_p2.py +++ b/UQ_LR_FS_p2.py @@ -73,22 +73,21 @@ parameters = [ # } {'fs__min_features_to_select': [1,2]}, - {'classifier': [LogisticRegression()], - #'classifier__C': np.logspace(0, 4, 10), - 'classifier__C': [2, 2.8], - 'classifier__max_iter': [100], - 'classifier__penalty': ['l1', 'l2'], - 'classifier__solver': ['saga'] + {'clf': [LogisticRegression(**rs)], + #'clf__C': np.logspace(0, 4, 10), + 'clf__C': [2, 2.8], + 'clf__max_iter': [100], + 'clf__penalty': ['l1', 'l2'], + 'clf__solver': ['saga'] } ] #%% Create pipeline pipeline = Pipeline([ - # ('pre', MinMaxScaler()) - ('fs', RFECV(LogisticRegression(**rs), scoring = 'matthews_corrcoef'))#cant be my mcc_fn - #, ('clf', ClfSwitcher()) - , ('classifier', ClfSwitcher()) - + ('pre', MinMaxScaler()) + , ('fs', RFECV(LogisticRegression(**rs), scoring = 'matthews_corrcoef'))#cant be my mcc_fn + #, ('clf', ClfSwitcher()) # gives me slightly lower results + #, ('clf', LogisticRegression(**rs)) ]) #%% diff --git a/uq_ml_models/UQ_LR_FS2.py b/uq_ml_models/UQ_LR_FS2.py index 91d28a5..61cca74 100644 --- a/uq_ml_models/UQ_LR_FS2.py +++ b/uq_ml_models/UQ_LR_FS2.py @@ -62,6 +62,7 @@ Created on Tue Mar 15 11:09:50 2022 ################ # NOTE: GS is going into pipeline, # Cannot get BEST model out +# https://stackoverflow.com/questions/55609339/how-to-perform-feature-selection-with-gridsearchcv-in-sklearn-in-python ################ # Create pipeline # pipeline = Pipeline([('pre', MinMaxScaler()) @@ -144,7 +145,6 @@ param_grid2 = [ 'clf__solver': ['saga'] } - ] # step 4: create pipeline pipeline = Pipeline([