def train_classifier(args): ''' Function that performs the detection of Parkinson :param args: Input arguments :return: ''' exp_name = args.exp_name subfolder = os.path.join( args.output, exp_name + '_' + datetime.datetime.now().strftime("%m_%d"), datetime.datetime.now().strftime("%H_%M")) file_result_patients = os.path.join(subfolder, 'res_pat.csv') file_result_segments = os.path.join(subfolder, 'res_seg.csv') model_file = os.path.join(subfolder, "model.json") if not os.path.exists(subfolder): os.makedirs(subfolder) val_results = Results(file_result_segments, file_result_patients) datas = Data(args.input_data, 1, 100, pk_level=False) for i in range(0, 10): lr = 0.001 model = multiple_cnn1D(datas.X_data.shape[2]) model_json = model.to_json() with open(model_file, "w") as json_file: json_file.write(model_json) print('fold', str(i)) datas.separate_fold(i) log_filename = os.path.join(subfolder, "training_" + str(i) + ".csv") w_filename = os.path.join(subfolder, "weights_" + str(i) + ".hdf5") model = train(model, datas, lr, log_filename, w_filename) print('Validation !!') val_results.validate_patient(model, datas.X_val, datas.y_val, datas.count_val)
def ablation_study(args): ''' Function that performs the ablation study :param args: Input arguments :return: ''' features = np.arange(1, 19) folder = os.path.join( args.output, args.exp_name + '_' + datetime.datetime.now().strftime("%m_%d"), datetime.datetime.now().strftime("%H_%M")) if not os.path.exists(folder): os.makedirs(folder) for j in range(1, 9): exp_name = args.exp_name + str(j) subfolder = os.path.join(folder, 'feature_' + str(j)) file_result_patients = os.path.join(subfolder, 'res_pat.csv') file_result_segments = os.path.join(subfolder, 'res_seg.csv') #filename = subfolder + "weights.hdf5" model_file = os.path.join(subfolder, "model.json") if not os.path.exists(subfolder): os.makedirs(subfolder) feature_delete = j feature_delete_r = j + 9 features_i = np.delete(features, [feature_delete, feature_delete_r]) val_results = Results(file_result_segments, file_result_patients) #datas = Datas(args.input_data, 1, 100, features=features_i) #datas.load(norm=None) datas = Data(args.input_data, 1, 100, pk_level=False) for i in range(0, 10): lr = 0.001 print('fold', str(i)) log_filename = os.path.join(subfolder, "training_" + str(i) + ".csv") w_filename = os.path.join(subfolder, "weights_" + str(i) + ".hdf5") datas.separate_fold(i) model = multiple_cnn1D(datas.X_data.shape[2]) model_json = model.to_json() with open(model_file, "w") as json_file: json_file.write(model_json) model = train(model, datas, lr, log_filename, w_filename) print('Validation !!!!!!!') val_results.validate_patient(model, datas.X_val, datas.y_val, datas.count_val)