python/methylnet/predictions.py
def make_prediction(train_pkl,test_pkl,input_vae_pkl,output_dir,cuda,interest_cols,categorical,disease_only,hidden_layer_topology,learning_rate_vae,learning_rate_mlp,weight_decay,dropout_p,n_epochs, scheduler='null', decay=0.5, t_max=10, eta_min=1e-6, t_mult=2, batch_size=50, val_pkl='val_methyl_array.pkl', n_workers=8, add_validation_set=False, loss_reduction='sum', hyperparameter_log='predictions/predict_hyperparameters_log.csv', job_name='predict_job', add_softmax=False, no_vae=False):
	"""Train prediction model by fine-tuning VAE and appending/training MLP to make classification/regression predictions on MethylationArrays."""
	hlt_list=filter(None,hidden_layer_topology.split(','))
	if hlt_list:
		hidden_layer_topology=list(map(int,hlt_list))
	else:
		hidden_layer_topology=[]
	latent_projection, Y_pred, Y_true, vae_mlp, scaling_factors = train_predict(train_pkl,test_pkl,input_vae_pkl,output_dir,cuda,list(interest_cols),categorical,disease_only,hidden_layer_topology,learning_rate_vae,learning_rate_mlp,weight_decay,dropout_p,n_epochs, scheduler, decay, t_max, eta_min, t_mult, batch_size, val_pkl, n_workers, add_validation_set, loss_reduction, add_softmax, no_vae)
	accuracy, precision, recall, f1 = -1,-1,-1,-1
	if categorical:
		from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
		accuracy, precision, recall, f1 = accuracy_score(Y_true,Y_pred), precision_score(Y_true,Y_pred,average='weighted'), recall_score(Y_true,Y_pred,average='weighted'), f1_score(Y_true,Y_pred,average='weighted')
	else:
		from sklearn.metrics import mean_squared_error, r2_score, explained_variance_score, mean_absolute_error
		accuracy, precision, recall, f1 = mean_squared_error(Y_true,Y_pred,multioutput='raw_values'), r2_score(Y_true,Y_pred,multioutput='raw_values'), explained_variance_score(Y_true,Y_pred,multioutput='raw_values'), mean_absolute_error(Y_true,Y_pred,multioutput='raw_values')
		if len(interest_cols)>1:
			accuracy, precision, recall, f1 = ';'.join([str(v) for v in accuracy]),';'.join([str(v) for v in precision]),';'.join([str(v) for v in recall]),';'.join([str(v) for v in f1])
		else:
			accuracy, precision, recall, f1=accuracy[0], precision[0], recall[0], f1[0]
	hyperparameter_row = [job_name,n_epochs, vae_mlp.best_epoch, vae_mlp.min_loss, vae_mlp.min_val_loss, vae_mlp.min_val_loss*scaling_factors['val'], accuracy, precision, recall, f1, vae_mlp.model.vae.n_input, vae_mlp.model.vae.n_latent, str(hidden_layer_topology), learning_rate_vae, learning_rate_mlp, weight_decay, scheduler, t_max, t_mult, eta_min, scaling_factors['train_batch_size'], scaling_factors['val_batch_size'], dropout_p]
	hyperparameter_df = pd.DataFrame(columns=['job_name','n_epochs',"best_epoch", "min_loss", "min_val_loss", "min_val_loss-batchsize_adj","test_accuracy" if categorical else 'neg_mean_squared_error', "test_precision" if categorical else 'r2_score', "test_recall" if categorical else 'explained_variance', "test_f1" if categorical else 'mean_absolute_error', "n_input", "n_latent", "hidden_layer_encoder_topology", "learning_rate_vae", "learning_rate_mlp", "weight_decay", "scheduler", "t_max", "t_mult", "eta_min","train_batch_size", "val_batch_size", "dropout_p"])
	hyperparameter_df.loc[0] = hyperparameter_row
	if os.path.exists(hyperparameter_log):
		print('APPEND')
		hyperparameter_df_former = pd.read_csv(hyperparameter_log)
		hyperparameter_df_former=hyperparameter_df_former[[col for col in list(hyperparameter_df) if not col.startswith('Unnamed')]]
		hyperparameter_df=pd.concat([hyperparameter_df_former,hyperparameter_df],axis=0)
	hyperparameter_df.to_csv(hyperparameter_log)
Train prediction model by fine-tuning VAE and appending/training MLP to make classification/regression predictions on MethylationArrays.
Train prediction model by fine-tuning VAE and appending/training MLP to make classification/regression predictions on MethylationArrays.
Train prediction model by fine - tuning VAE and appending / training MLP to make classification / regression predictions on MethylationArrays .
def make_prediction(train_pkl,test_pkl,input_vae_pkl,output_dir,cuda,interest_cols,categorical,disease_only,hidden_layer_topology,learning_rate_vae,learning_rate_mlp,weight_decay,dropout_p,n_epochs, scheduler='null', decay=0.5, t_max=10, eta_min=1e-6, t_mult=2, batch_size=50, val_pkl='val_methyl_array.pkl', n_workers=8, add_validation_set=False, loss_reduction='sum', hyperparameter_log='predictions/predict_hyperparameters_log.csv', job_name='predict_job', add_softmax=False, no_vae=False):
	hlt_list=filter(None,hidden_layer_topology.split(','))
	if hlt_list:
		hidden_layer_topology=list(map(int,hlt_list))
	else:
		hidden_layer_topology=[]
	latent_projection, Y_pred, Y_true, vae_mlp, scaling_factors = train_predict(train_pkl,test_pkl,input_vae_pkl,output_dir,cuda,list(interest_cols),categorical,disease_only,hidden_layer_topology,learning_rate_vae,learning_rate_mlp,weight_decay,dropout_p,n_epochs, scheduler, decay, t_max, eta_min, t_mult, batch_size, val_pkl, n_workers, add_validation_set, loss_reduction, add_softmax, no_vae)
	accuracy, precision, recall, f1 = -1,-1,-1,-1
	if categorical:
		from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
		accuracy, precision, recall, f1 = accuracy_score(Y_true,Y_pred), precision_score(Y_true,Y_pred,average='weighted'), recall_score(Y_true,Y_pred,average='weighted'), f1_score(Y_true,Y_pred,average='weighted')
	else:
		from sklearn.metrics import mean_squared_error, r2_score, explained_variance_score, mean_absolute_error
		accuracy, precision, recall, f1 = mean_squared_error(Y_true,Y_pred,multioutput='raw_values'), r2_score(Y_true,Y_pred,multioutput='raw_values'), explained_variance_score(Y_true,Y_pred,multioutput='raw_values'), mean_absolute_error(Y_true,Y_pred,multioutput='raw_values')
		if len(interest_cols)>1:
			accuracy, precision, recall, f1 = ';'.join([str(v) for v in accuracy]),';'.join([str(v) for v in precision]),';'.join([str(v) for v in recall]),';'.join([str(v) for v in f1])
		else:
			accuracy, precision, recall, f1=accuracy[0], precision[0], recall[0], f1[0]
	hyperparameter_row = [job_name,n_epochs, vae_mlp.best_epoch, vae_mlp.min_loss, vae_mlp.min_val_loss, vae_mlp.min_val_loss*scaling_factors['val'], accuracy, precision, recall, f1, vae_mlp.model.vae.n_input, vae_mlp.model.vae.n_latent, str(hidden_layer_topology), learning_rate_vae, learning_rate_mlp, weight_decay, scheduler, t_max, t_mult, eta_min, scaling_factors['train_batch_size'], scaling_factors['val_batch_size'], dropout_p]
	hyperparameter_df = pd.DataFrame(columns=['job_name','n_epochs',"best_epoch", "min_loss", "min_val_loss", "min_val_loss-batchsize_adj","test_accuracy" if categorical else 'neg_mean_squared_error', "test_precision" if categorical else 'r2_score', "test_recall" if categorical else 'explained_variance', "test_f1" if categorical else 'mean_absolute_error', "n_input", "n_latent", "hidden_layer_encoder_topology", "learning_rate_vae", "learning_rate_mlp", "weight_decay", "scheduler", "t_max", "t_mult", "eta_min","train_batch_size", "val_batch_size", "dropout_p"])
	hyperparameter_df.loc[0] = hyperparameter_row
	if os.path.exists(hyperparameter_log):
		print('APPEND')
		hyperparameter_df_former = pd.read_csv(hyperparameter_log)
		hyperparameter_df_former=hyperparameter_df_former[[col for col in list(hyperparameter_df) if not col.startswith('Unnamed')]]
		hyperparameter_df=pd.concat([hyperparameter_df_former,hyperparameter_df],axis=0)
	hyperparameter_df.to_csv(hyperparameter_log)
def make_prediction ( train_pkl , test_pkl , input_vae_pkl , output_dir , cuda , interest_cols , categorical , disease_only , hidden_layer_topology , learning_rate_vae , learning_rate_mlp , weight_decay , dropout_p , n_epochs , scheduler = 'null' , decay = 0.5 , t_max = 10 , eta_min = 1e-6 , t_mult = 2 , batch_size = 50 , val_pkl = 'val_methyl_array.pkl' , n_workers = 8 , add_validation_set = False , loss_reduction = 'sum' , hyperparameter_log = 'predictions/predict_hyperparameters_log.csv' , job_name = 'predict_job' , add_softmax = False , no_vae = False ) : hlt_list = filter ( None , hidden_layer_topology . split ( ',' ) ) if hlt_list : hidden_layer_topology = list ( map ( int , hlt_list ) ) else : hidden_layer_topology = [ ] latent_projection , Y_pred , Y_true , vae_mlp , scaling_factors = train_predict ( train_pkl , test_pkl , input_vae_pkl , output_dir , cuda , list ( interest_cols ) , categorical , disease_only , hidden_layer_topology , learning_rate_vae , learning_rate_mlp , weight_decay , dropout_p , n_epochs , scheduler , decay , t_max , eta_min , t_mult , batch_size , val_pkl , n_workers , add_validation_set , loss_reduction , add_softmax , no_vae ) accuracy , precision , recall , f1 = - 1 , - 1 , - 1 , - 1 if categorical : from sklearn . metrics import accuracy_score , precision_score , recall_score , f1_score accuracy , precision , recall , f1 = accuracy_score ( Y_true , Y_pred ) , precision_score ( Y_true , Y_pred , average = 'weighted' ) , recall_score ( Y_true , Y_pred , average = 'weighted' ) , f1_score ( Y_true , Y_pred , average = 'weighted' ) else : from sklearn . metrics import mean_squared_error , r2_score , explained_variance_score , mean_absolute_error accuracy , precision , recall , f1 = mean_squared_error ( Y_true , Y_pred , multioutput = 'raw_values' ) , r2_score ( Y_true , Y_pred , multioutput = 'raw_values' ) , explained_variance_score ( Y_true , Y_pred , multioutput = 'raw_values' ) , mean_absolute_error ( Y_true , Y_pred , multioutput = 'raw_values' ) if len ( interest_cols ) > 1 : accuracy , precision , recall , f1 = ';' . join ( [ str ( v ) for v in accuracy ] ) , ';' . join ( [ str ( v ) for v in precision ] ) , ';' . join ( [ str ( v ) for v in recall ] ) , ';' . join ( [ str ( v ) for v in f1 ] ) else : accuracy , precision , recall , f1 = accuracy [ 0 ] , precision [ 0 ] , recall [ 0 ] , f1 [ 0 ] hyperparameter_row = [ job_name , n_epochs , vae_mlp . best_epoch , vae_mlp . min_loss , vae_mlp . min_val_loss , vae_mlp . min_val_loss * scaling_factors [ 'val' ] , accuracy , precision , recall , f1 , vae_mlp . model . vae . n_input , vae_mlp . model . vae . n_latent , str ( hidden_layer_topology ) , learning_rate_vae , learning_rate_mlp , weight_decay , scheduler , t_max , t_mult , eta_min , scaling_factors [ 'train_batch_size' ] , scaling_factors [ 'val_batch_size' ] , dropout_p ] hyperparameter_df = pd . DataFrame ( columns = [ 'job_name' , 'n_epochs' , "best_epoch" , "min_loss" , "min_val_loss" , "min_val_loss-batchsize_adj" , "test_accuracy" if categorical else 'neg_mean_squared_error' , "test_precision" if categorical else 'r2_score' , "test_recall" if categorical else 'explained_variance' , "test_f1" if categorical else 'mean_absolute_error' , "n_input" , "n_latent" , "hidden_layer_encoder_topology" , "learning_rate_vae" , "learning_rate_mlp" , "weight_decay" , "scheduler" , "t_max" , "t_mult" , "eta_min" , "train_batch_size" , "val_batch_size" , "dropout_p" ] ) hyperparameter_df . loc [ 0 ] = hyperparameter_row if os . path . exists ( hyperparameter_log ) : print ( 'APPEND' ) hyperparameter_df_former = pd . read_csv ( hyperparameter_log ) hyperparameter_df_former = hyperparameter_df_former [ [ col for col in list ( hyperparameter_df ) if not col . startswith ( 'Unnamed' ) ] ] hyperparameter_df = pd . concat ( [ hyperparameter_df_former , hyperparameter_df ] , axis = 0 ) hyperparameter_df . to_csv ( hyperparameter_log )
Train prediction model by fine-tuning VAE and appending/training MLP to make classification/regression predictions on MethylationArrays.
Train prediction model by fine - tuning VAE and appending / training MLP to make classification / regression predictions on MethylationArrays .
"""Train prediction model by fine-tuning VAE and appending/training MLP to make classification/regression predictions on MethylationArrays."""
train_pkl
test_pkl
input_vae_pkl
output_dir
cuda
interest_cols
categorical
disease_only
hidden_layer_topology
learning_rate_vae
learning_rate_mlp
weight_decay
dropout_p
n_epochs
scheduler
decay
t_max
eta_min
t_mult
batch_size
val_pkl
n_workers
add_validation_set
loss_reduction
hyperparameter_log
job_name
add_softmax
no_vae