aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
This commit is contained in:
parent
6db5046302
commit
95852fa40e
4 changed files with 589 additions and 21 deletions
55
UQ_FS_eg.py
55
UQ_FS_eg.py
|
@ -68,7 +68,6 @@ pipe = Pipeline([
|
|||
('pre', MinMaxScaler())
|
||||
# , ('fs', RFECV(LogisticRegression(**rs), cv = cv, scoring = 'matthews_corrcoef'))
|
||||
, ('fs', RFECV(DecisionTreeClassifier(**rs), cv = cv, scoring = 'matthews_corrcoef'))
|
||||
|
||||
, ('clf', LogisticRegression(**rs))])
|
||||
|
||||
search_space = [
|
||||
|
@ -204,7 +203,7 @@ print('\nAccuracy on Blind test:', round(accuracy_score(y_bts, bts_predict),2))
|
|||
bts_mcc_score = round(matthews_corrcoef(y_bts, bts_predict),2)
|
||||
|
||||
# Diff b/w train and bts test scores
|
||||
train_test_diff = train_bscore - bts_mcc
|
||||
train_test_diff = train_bscore - bts_mcc_score
|
||||
print('\nDiff b/w train and blind test score (MCC):', train_test_diff)
|
||||
|
||||
|
||||
|
@ -232,16 +231,25 @@ lr_btsD
|
|||
#===========================
|
||||
# Add FS related model info
|
||||
#===========================
|
||||
output_modelD = {'model_name': model_name
|
||||
model_namef = str(model_name)
|
||||
# FIXME: doesn't tell you which it has chosen
|
||||
fs_methodf = str(gscv_fs.best_estimator_.named_steps['fs'])
|
||||
all_featuresL = list(all_features)
|
||||
fs_res_arrayf = str(list( gscv_fs.best_estimator_.named_steps['fs'].get_support()))
|
||||
fs_res_array_rankf = list( gscv_fs.best_estimator_.named_steps['fs'].ranking_)
|
||||
sel_featuresf = list(sel_features)
|
||||
n_sf = int(n_sf)
|
||||
|
||||
output_modelD = {'model_name': model_namef
|
||||
, 'model_refit_param': mod_refit_param
|
||||
, 'Best_model_params': b_model_params
|
||||
, 'n_all_features': n_all_features
|
||||
, 'fs_method': gscv_fs.best_estimator_.named_steps['fs'] # FIXME: doesn't tell you which it has chosen
|
||||
, 'fs_res_array': gscv_fs.best_estimator_.named_steps['fs'].get_support()
|
||||
, 'fs_res_array_rank': gscv_fs.best_estimator_.named_steps['fs'].ranking_
|
||||
, 'all_feature_names': all_features
|
||||
, 'fs_method': fs_methodf
|
||||
, 'fs_res_array': fs_res_arrayf
|
||||
, 'fs_res_array_rank': fs_res_array_rankf
|
||||
, 'all_feature_names': all_featuresL
|
||||
, 'n_sel_features': n_sf
|
||||
, 'sel_features_names': sel_features}
|
||||
, 'sel_features_names': sel_featuresf}
|
||||
output_modelD
|
||||
|
||||
#========================================
|
||||
|
@ -252,18 +260,33 @@ output_modelD
|
|||
|
||||
output_modelD['train_score (MCC)'] = train_bscore
|
||||
output_modelD['bts_mcc'] = bts_mcc_score
|
||||
output_modelD['train_bts_diff'] = train_test_diff
|
||||
output_modelD['train_bts_diff'] = round(train_test_diff,2)
|
||||
output_modelD
|
||||
|
||||
class NpEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, np.integer):
|
||||
return int(obj)
|
||||
if isinstance(obj, np.floating):
|
||||
return float(obj)
|
||||
if isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
return super(NpEncoder, self).default(obj)
|
||||
|
||||
json.dumps(output_modelD, cls=NpEncoder)
|
||||
|
||||
#========================================
|
||||
# Write final output file
|
||||
# https://stackoverflow.com/questions/19201290/how-to-save-a-dictionary-to-a-file
|
||||
#========================================
|
||||
# output final dict as a json
|
||||
# outFile = 'LR_FS.json'
|
||||
# with open(outFile, 'w') as f:
|
||||
# json.dump(output_modelD, f)
|
||||
# #
|
||||
# with open(file, 'r') as f:
|
||||
# data = json.load(f)
|
||||
#output final dict as a json
|
||||
outFile = 'LR_FS.json'
|
||||
with open(outFile, 'w') as f:
|
||||
f.write(json.dumps(output_modelD,cls=NpEncoder))
|
||||
|
||||
# read json
|
||||
file = 'LR_FS.json'
|
||||
with open(file, 'r') as f:
|
||||
data = json.load(f)
|
||||
##############################################################################
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue