multiple changes

This commit is contained in:
Tanushree Tunstall 2022-07-02 10:25:42 +01:00
parent 2fda32901b
commit dccd3c8eb2
7 changed files with 82 additions and 122 deletions

View file

@ -51,17 +51,17 @@ split_data_types = ['actual', 'complete']
fs_models = [('AdaBoost Classifier' , AdaBoostClassifier(**rs) )
, ('Decision Tree' , DecisionTreeClassifier(**rs) )
, ('Extra Tree' , ExtraTreeClassifier(**rs) )
, ('Extra Trees' , ExtraTreesClassifier(**rs) )
, ('Gradient Boosting' , GradientBoostingClassifier(**rs) )
, ('LDA' , LinearDiscriminantAnalysis() )
, ('Logistic Regression' , LogisticRegression(**rs) )
, ('Logistic RegressionCV' , LogisticRegressionCV(cv = 3, **rs))
, ('Passive Aggresive' , PassiveAggressiveClassifier(**rs, **njobs) )
, ('Random Forest' , RandomForestClassifier(**rs, n_estimators = 1000 ) )
, ('Ridge Classifier' , RidgeClassifier(**rs) )
, ('Ridge ClassifierCV' , RidgeClassifierCV(cv = 3) )
, ('Stochastic GDescent' , SGDClassifier(**rs, **njobs) )
#, ('Extra Tree' , ExtraTreeClassifier(**rs) )
#, ('Extra Trees' , ExtraTreesClassifier(**rs) )
#, ('Gradient Boosting' , GradientBoostingClassifier(**rs) )
#, ('LDA' , LinearDiscriminantAnalysis() )
#, ('Logistic Regression' , LogisticRegression(**rs) )
#, ('Logistic RegressionCV' , LogisticRegressionCV(cv = 3, **rs))
#, ('Passive Aggresive' , PassiveAggressiveClassifier(**rs, **njobs) )
#, ('Random Forest' , RandomForestClassifier(**rs, n_estimators = 1000 ) )
#, ('Ridge Classifier' , RidgeClassifier(**rs) )
#, ('Ridge ClassifierCV' , RidgeClassifierCV(cv = 3) )
#, ('Stochastic GDescent' , SGDClassifier(**rs, **njobs) )
]
for gene, drug in ml_gene_drugD.items():
@ -78,7 +78,7 @@ for gene, drug in ml_gene_drugD.items():
for split_type in split_types:
for data_type in split_data_types:
# unused per-split outfile
out_filename = outdir + gene.lower() + '_'+split_type+'_' + data_type + '.json'
#out_filename = outdir + gene.lower() + '_'+split_type+'_' + data_type + '.json'
tempD=split_tts(gene_dataD[gene_low]
, data_type = data_type
, split_type = split_type
@ -122,41 +122,25 @@ for gene, drug in ml_gene_drugD.items():
, '\nModel func:' , model_fn)
#, '\nList of models:', models)
index = index+1
out_fsD[model_name] = {}
# current_model = {}
#out_fsD[model_name] = {}
current_model = {}
for k, v in paramD.items():
# out_filename = (gene.lower() + '_' + split_type + '_' + data_type + '_' + k + '.json')
out_filename = (gene.lower() + '_' + split_type + '_' + data_type + '_' + model_name + '_' + k + '.json')
fsD_params=paramD[k]
# print("XXXXXX THIS: ", len(fsD_params['input_df']) )
# print("XXXXXX THIS: ", out_filename )
# current_model[k] = fsgs_rfecv(
out_fsD[model_name][k] = fsgs_rfecv(
#out_fsD[model_name][k] = fsgs_rfecv(
thingg = foo(
)
current_model[k] = fsgs_rfecv(
**fsD_params
, param_gridLd = [{'fs__min_features_to_select': [1]}]
, blind_test_df = tempD['X_bts']
, blind_test_target = tempD['y_bts']
, estimator = model_fn
, use_fs = False # uses estimator as the RFECV parameter for fs. Set to TRUE if you want to supply custom_fs as shown below
# NOTE: IS THIS CORRECT?!?
, custom_fs = RFECV(DecisionTreeClassifier(**rs), cv = skf_cv, scoring = 'matthews_corrcoef')
, cv_method = skf_cv
)
# write per-resampler outfile here
# with open(out_filename, 'w') as f:
# f.write(json.dumps(current_model
# , cls = NpEncoder )
# )
# write per-split outfile here
with open(out_filename, 'w') as f:
f.write(json.dumps(out_fsD
#, cls = NpEncoder
))
#%%############################################################################
# # Read output json
# testF = outdir + 'pnca_70_30_actual.json'
# testF = outdir + 'pnca_70_30_complete.json'
# with open(testF, 'r') as f:
# data = json.load(f)
with open(out_filename, 'w') as f:
f.write(json.dumps(current_model)