added and ran hyperparam script for all different classifiers, but couldn't successfully run the feature selection and hyperparam together

This commit is contained in:
Tanushree Tunstall 2022-05-20 08:09:24 +01:00
parent 74af5ef890
commit 37bda41f44
18 changed files with 131 additions and 142 deletions

View file

@ -33,13 +33,12 @@ class ClfSwitcher(BaseEstimator):
parameters = [
{
'clf__estimator': [BaggingClassifier(**rs
, **njobs
, bootstrap = True
, oob_score = True)],
, 'clf__estimator__n_estimators' : [10, 100, 1000]
, **njobs
, bootstrap = True
, oob_score = True)]
, 'clf__estimator__n_estimators' : [10, 25, 50, 100, 150, 200, 500, 700, 1000]
# If None, then the base estimator is a DecisionTreeClassifier.
, 'clf__estimator__base_estimator' : ['None', 'SVC()', 'KNeighborsClassifier()']# if none, DT is used
, 'clf__estimator__gamma': ['scale', 'auto']
#, 'clf__estimator__base_estimator' : ['None', 'SVC()', 'KNeighborsClassifier()']# if none, DT is used
}
]
@ -68,7 +67,7 @@ gscv_bc_fit_be_res = gscv_bc_fit.cv_results_
print('Best model:\n', gscv_bc_fit_be_mod)
print('Best models score:\n', gscv_bc_fit.best_score_, ':' , round(gscv_bc_fit.best_score_, 2))
print('\nMean test score from fit results:', round(mean(gscv_bc_fit_be_re['mean_test_mcc']),2))
print('\nMean test score from fit results:', round(mean(gscv_bc_fit_be_res['mean_test_mcc']),2))
print('\nMean test score from fit results:', round(np.nanmean(gscv_bc_fit_be_res['mean_test_mcc']),2))
######################################
@ -106,17 +105,15 @@ bc_bts_dict['bts_jaccard'] = round(jaccard_score(y_bts, test_predict),2)
bc_bts_dict
# Create a df from dict with all scores
pd.DataFrame.from_dict(bc_bts_dict, orient = 'index', columns = 'best_model')
bc_bts_df = pd.DataFrame.from_dict(bc_bts_dict,orient = 'index')
bc_bts_df.columns = ['Logistic_Regression']
bc_bts_df.columns = ['BC']
print(bc_bts_df)
# Create df with best model params
model_params = pd.Series(['best_model_params', list(gscv_bc_fit_be_mod.items() )])
model_params_df = model_params.to_frame()
model_params_df
model_params_df.columns = ['Logistic_Regression']
model_params_df.columns = ['BC']
model_params_df.columns
# Combine the df of scores and the best model params