iterator
This commit is contained in:
parent
01ff9d5be6
commit
4d5b848471
1 changed files with 36 additions and 31 deletions
|
@ -9,7 +9,7 @@ import sys, os
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import re
|
import re
|
||||||
#import prettyprint as pp
|
#import prettyprint as pp
|
||||||
###############################################################################
|
###############################################################################
|
||||||
homedir = os.path.expanduser("~")
|
homedir = os.path.expanduser("~")
|
||||||
sys.path.append(homedir + '/git/LSHTM_analysis/scripts/ml/ml_functions')
|
sys.path.append(homedir + '/git/LSHTM_analysis/scripts/ml/ml_functions')
|
||||||
|
@ -18,7 +18,7 @@ sys.path
|
||||||
outdir = homedir + '/git/LSHTM_ML/output/fs/'
|
outdir = homedir + '/git/LSHTM_ML/output/fs/'
|
||||||
|
|
||||||
#====================
|
#====================
|
||||||
# Import ML functions
|
# Import ML functions
|
||||||
#====================
|
#====================
|
||||||
|
|
||||||
from MultClfs import *
|
from MultClfs import *
|
||||||
|
@ -27,43 +27,45 @@ from SplitTTS import *
|
||||||
from FS import *
|
from FS import *
|
||||||
# param dict for getmldata()
|
# param dict for getmldata()
|
||||||
combined_model_paramD = {'data_combined_model' : False
|
combined_model_paramD = {'data_combined_model' : False
|
||||||
, 'use_or' : False
|
, 'use_or' : False
|
||||||
, 'omit_all_genomic_features': False
|
, 'omit_all_genomic_features': False
|
||||||
, 'write_maskfile' : False
|
, 'write_maskfile' : False
|
||||||
, 'write_outfile' : False }
|
, 'write_outfile' : False }
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#ml_genes = ["pncA", "embB", "katG", "rpoB", "gid"]
|
#ml_genes = ["pncA", "embB", "katG", "rpoB", "gid"]
|
||||||
# outdir = homedir + '/git/Data/ml_combined/fs/'
|
# outdir = homedir + '/git/Data/ml_combined/fs/'
|
||||||
|
|
||||||
ml_gene_drugD = {'pncA' : 'pyrazinamide'
|
ml_gene_drugD = {
|
||||||
# , 'embB' : 'ethambutol'
|
'pncA' : 'pyrazinamide', # NOTE: may need re-run for 80_20 and sl
|
||||||
# , 'katG' : 'isoniazid'
|
#'embB' : 'ethambutol',
|
||||||
# , 'rpoB' : 'rifampicin'
|
#'katG' : 'isoniazid', #NOTE: RF only for all split-types actual
|
||||||
# , 'gid' : 'streptomycin'
|
#'rpoB' : 'rifampicin',
|
||||||
}
|
#'gid' : 'streptomycin' # NOTE: for gid, run 'actual' on 80/20 and sl only
|
||||||
|
}
|
||||||
gene_dataD={}
|
gene_dataD={}
|
||||||
# NOTE: for gid, run 'actual' on 80/20 and sl only
|
|
||||||
split_types = ['70_30', '80_20', 'sl']
|
#split_types = ['70_30', '80_20', 'sl']
|
||||||
split_data_types = ['actual', 'complete']
|
|
||||||
#split_types = ['70_30']
|
|
||||||
#split_data_types = ['actual', 'complete']
|
#split_data_types = ['actual', 'complete']
|
||||||
|
|
||||||
#fs_models = [('Logistic Regression' , LogisticRegression(**rs) )]
|
split_types = ['70_30']
|
||||||
|
#split_data_types = ['actual', 'complete']
|
||||||
|
split_data_types = ['actual']
|
||||||
|
|
||||||
fs_models = [
|
fs_models = [
|
||||||
('Logistic Regression' , LogisticRegression(**rs) )
|
#('Ridge Classifier' , RidgeClassifier(**rs) ),
|
||||||
, ('Ridge Classifier' , RidgeClassifier(**rs) )
|
#('Ridge ClassifierCV' , RidgeClassifierCV(cv = 3) ),
|
||||||
#, ('AdaBoost Classifier' , AdaBoostClassifier(**rs) )
|
#('Logistic Regression' , LogisticRegression(**rs, **njobs) ),
|
||||||
#, ('Decision Tree' , DecisionTreeClassifier(**rs) )
|
#('AdaBoost Classifier' , AdaBoostClassifier(**rs) ),
|
||||||
#, ('Extra Tree' , ExtraTreeClassifier(**rs) )
|
#('Gradient Boosting' , GradientBoostingClassifier(**rs) ),
|
||||||
#, ('Extra Trees' , ExtraTreesClassifier(**rs) )
|
#('Stochastic GDescent' , SGDClassifier(**rs, **njobs) ),
|
||||||
#, ('Gradient Boosting' , GradientBoostingClassifier(**rs) )
|
#('Decision Tree' , DecisionTreeClassifier(**rs) ),
|
||||||
#, ('LDA' , LinearDiscriminantAnalysis() )
|
#('Extra Trees' , ExtraTreesClassifier(**rs, **njobs) ),
|
||||||
#, ('Logistic RegressionCV' , LogisticRegressionCV(cv = 3, **rs))
|
#('Extra Tree' , ExtraTreeClassifier(**rs) ),
|
||||||
#, ('Passive Aggresive' , PassiveAggressiveClassifier(**rs, **njobs) )
|
#('LDA' , LinearDiscriminantAnalysis() ),
|
||||||
#, ('Random Forest' , RandomForestClassifier(**rs, n_estimators = 1000 ) )
|
#('Logistic RegressionCV' , LogisticRegressionCV(cv = 3, **rs, **njobs) ),
|
||||||
#, ('Ridge ClassifierCV' , RidgeClassifierCV(cv = 3) )
|
#('Passive Aggresive' , PassiveAggressiveClassifier(**rs, **njobs) )
|
||||||
#, ('Stochastic GDescent' , SGDClassifier(**rs, **njobs) )
|
#('Random Forest' , RandomForestClassifier(n_estimators = 1000, verbose=3, **rs, **njobs ) )
|
||||||
|
('XGBoost' , XGBClassifier(verbosity=3, use_label_encoder=False, **rs, **njobs) )
|
||||||
]
|
]
|
||||||
|
|
||||||
for gene, drug in ml_gene_drugD.items():
|
for gene, drug in ml_gene_drugD.items():
|
||||||
|
@ -122,9 +124,10 @@ for gene, drug in ml_gene_drugD.items():
|
||||||
index = index+1
|
index = index+1
|
||||||
#out_fsD[model_name] = {}
|
#out_fsD[model_name] = {}
|
||||||
current_model = {}
|
current_model = {}
|
||||||
|
model_name_clean = model_name.replace(' ','-')
|
||||||
|
|
||||||
for k, v in paramD.items():
|
for k, v in paramD.items():
|
||||||
out_filename = gene.lower() + '_' + split_type + '_' + data_type + '_' + model_name + '_' + k + '.json'
|
out_filename = outdir + gene.lower() + '_' + split_type + '_' + data_type + '_' + model_name_clean + '_' + k + '.json'
|
||||||
fsD_params=paramD[k]
|
fsD_params=paramD[k]
|
||||||
|
|
||||||
#out_fsD[model_name][k] = fsgs_rfecv(
|
#out_fsD[model_name][k] = fsgs_rfecv(
|
||||||
|
@ -145,6 +148,8 @@ for gene, drug in ml_gene_drugD.items():
|
||||||
|
|
||||||
# write current model to disk
|
# write current model to disk
|
||||||
#print(current_model)
|
#print(current_model)
|
||||||
|
print("⚠️ ⚠️ ⚠️ WRITING TO FILE: ", out_filename, "⚠️ ⚠️ ⚠️'")
|
||||||
out_json = json.dumps(current_model)
|
out_json = json.dumps(current_model)
|
||||||
with open(out_filename, 'w', encoding="utf-8") as file:
|
with open(out_filename, 'w', encoding="utf-8") as file:
|
||||||
file.write(out_json)
|
file.write(out_json)
|
||||||
|
print("⚠️ ⚠️ ⚠️ Finished writing to: ", out_filename, "⚠️ ⚠️ ⚠️'")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue