# # ############ Calculate SDRR of clean data ######################### # # #RR_sec_detrended is in ms and std_dev will be in ms # sdrr_curr=np.std(RR_sec_detrended_ms); #print("SDRR after filtering and detrending in ms for " + rec_name + "is: " + str(sdrr_curr)); #################### PLOT histograms for each record ############################################## # fig_hist,plot_hist=graphs.plotHistPercent(rec_name, RR_sec,100, "RR (sec)", "Percentage of total points", "RR interval histogram") # fig_hist.savefig(output_folder+"hist_"+record+".png") # plt.close(); ################### Append feature for 1 record to a list of lists ############################## all_features.append(feature_rec) #nlm.plot_ctm(rec_name_array,ctm_list_list,radius_array) #nlm.plot_dist(rec_name_array,dist_list_list,radius_array) rw.write_value(global_vocab, output_folder, 'global_vocab.txt', 'w') print(len(all_features)) #write to all_features to file rw.write_value(all_features, output_folder, "all_features_readable.txt", 'w') rw.write_features_to_file(all_features, output_folder, "all_features_pickle.txt") rw.write_features_to_file(global_vocab, output_folder, "global_vocab_pickle.txt") rw.write_features_to_file(rec_name_array, output_folder, "rec_name_array_pickle.txt") #plt.show()
# #RR_sec_detrended is in ms and std_dev will be in ms # sdrr_curr=np.std(RR_sec_detrended_ms); #print("SDRR after filtering and detrending in ms for " + rec_name + "is: " + str(sdrr_curr)); #################### PLOT histograms for each record ############################################## # fig_hist,plot_hist=graphs.plotHistPercent(rec_name, RR_sec,100, "RR (sec)", "Percentage of total points", "RR interval histogram") # fig_hist.savefig(output_folder+"hist_"+record+".png") # plt.close(); ################### Append feature for 1 record to a list of lists ############################## all_features.append(feature_rec) #nlm.plot_ctm(rec_name_array,ctm_list_list,radius_array) #nlm.plot_dist(rec_name_array,dist_list_list,radius_array) rw.write_value(global_vocab, output_folder, 'global_vocab.txt', 'w') print(len(all_features)) #write to all_features to file rw.write_value(all_features,output_folder,"all_features_readable.txt",'w') rw.write_features_to_file(all_features,output_folder,"all_features_pickle.txt") rw.write_features_to_file(global_vocab,output_folder,"global_vocab_pickle.txt") rw.write_features_to_file(rec_name_array, output_folder, "rec_name_array_pickle.txt") plt.show()
# cl.print_classification_report(y_test_report_rfecv_cv, y_predicted_report_rfecv_cv,['class 0', 'class 1']) print("############################################") folds=5 cv = StratifiedKFold(y_eval, n_folds=folds) classifier = svm.SVC(kernel='linear', probability=True) ###################### Feature selection using RFECV only ################################################# only_feature_selection,index_arr_onlyfs=cl.select_optimal_features(X_cv_normalized_matrix,y_cv,classifier) print("number of features selected only with rfecv: " +str(len(index_arr_onlyfs))) index_num_fs_only,index_freq_fs_only=cl.sort_and_combine_feature_indices(index_arr_onlyfs) print("index numbers are: " + str(index_num_fs_only)) rw.write_features_to_file(index_num_fs_only,output_folder,"rfecv_selected13_features.txt") #print("index freq are: " + str(index_freq_fs_only)) ####### print features selected by rfecv alone ######################################### rfecv_only_feature_arr=[] for val in index_num_fs_only: #print val #print (inv_global_vocab[val]) rfecv_only_feature_arr.append(inv_global_vocab[val]) print("len of rfecv only features is: " +str(len(rfecv_only_feature_arr))) np.savetxt(output_folder+"rfecv_only_features.txt",rfecv_only_feature_arr,fmt="%s",delimiter=',',newline='\n') ####################################################################### #plt.figure()
folds = 5 cv = StratifiedKFold(y_eval, n_folds=folds) classifier = svm.SVC(kernel='linear', probability=True) ###################### Feature selection using RFECV only ################################################# only_feature_selection, index_arr_onlyfs = cl.select_optimal_features( X_cv_normalized_matrix, y_cv, classifier) print("number of features selected only with rfecv: " + str(len(index_arr_onlyfs))) index_num_fs_only, index_freq_fs_only = cl.sort_and_combine_feature_indices( index_arr_onlyfs) print("index numbers are: " + str(index_num_fs_only)) rw.write_features_to_file(index_num_fs_only, output_folder, "rfecv_selected13_features.txt") #print("index freq are: " + str(index_freq_fs_only)) ####### print features selected by rfecv alone ######################################### rfecv_only_feature_arr = [] for val in index_num_fs_only: #print val #print (inv_global_vocab[val]) rfecv_only_feature_arr.append(inv_global_vocab[val]) print("len of rfecv only features is: " + str(len(rfecv_only_feature_arr))) np.savetxt(output_folder + "rfecv_only_features.txt", rfecv_only_feature_arr, fmt="%s", delimiter=',', newline='\n')