def cife(): before = datetime.datetime.now() result = CIFE.cife(data, labels, mode="index", n_selected_features=treshold) after = datetime.datetime.now() print("CIFE") print(len(result)) print("cas: " + str(after - before)) print('\n') if len(result) < len(header): transform_and_save(result, "CIFE")
def main(): # load data mat = scipy.io.loadmat('../data/colon.mat') X = mat['X'] # data X = X.astype(float) y = mat['Y'] # label y = y[:, 0] n_samples, n_features = X.shape # number of samples and number of features # split data into 10 folds ss = cross_validation.KFold(n_samples, n_folds=10, shuffle=True) # perform evaluation on classification task num_fea = 10 # number of selected features clf = svm.LinearSVC() # linear SVM correct = 0 for train, test in ss: # obtain the index of each feature on the training set idx = CIFE.cife(X[train], y[train], n_selected_features=num_fea) # obtain the dataset on the selected features features = X[:, idx[0:num_fea]] # train a classification model with the selected features on the training dataset clf.fit(features[train], y[train]) # predict the class labels of test data y_predict = clf.predict(features[test]) # obtain the classification accuracy on the test data acc = accuracy_score(y[test], y_predict) correct = correct + acc # output the average classification accuracy over all 10 folds print 'Accuracy:', float(correct) / 10
def compute_cife_score(train_features, train_labels): # no score available for CIFE extraction idx, score, _ = CIFE.cife(train_features, train_labels, n_selected_features=10) return score, idx
def CIFE_FS(X_train, y_train): F, J_CMI, MIfy = CIFE.cife(X_train, y_train, n_selected_features=num_fea) return (F)
sheet_test.write(r, c, roc_auc_score(Y_test, Y_pred)) r = r + 1 c = c + 1 r = 0 MV_sel = [] MV_sel.append(('MIM', MIM.mim(X_train, Y_train, n_selected_features=num_fea))) print('MIM') MV_sel.append(('MIFS', MIFS.mifs(X_train, Y_train, n_selected_features=num_fea))) print('MIFS') MV_sel.append(('MRMR', MRMR.mrmr(X_train, Y_train, n_selected_features=num_fea))) print('MRMR') MV_sel.append(('CIFE', CIFE.cife(X_train, Y_train, n_selected_features=num_fea))) print('CIFE') MV_sel.append(('JMI', JMI.jmi(X_train, Y_train, n_selected_features=num_fea))) print('JMI') MV_sel.append(('CMIM', CMIM.cmim(X_train, Y_train, n_selected_features=num_fea))) print('CMIM') MV_sel.append(('ICAP', ICAP.icap(X_train, Y_train, n_selected_features=num_fea))) print('ICAP') MV_sel.append(('DISR', DISR.disr(X_train, Y_train, n_selected_features=num_fea))) for name, model in models: for kind, idx in MV_sel: #print(idx[0:num_fea][0])
for i in range(n_selected_features): idx.append(pval[i][0]) return idx # MULTIVARIATE FEATURE SELECTION X CLASSIFICATION (10 fold CV) # print('BEFORE') MV_sel = [] MV_sel.append(('WLCX', WLCX(X, Y, n_selected_features=num_fea))) print('WLCX') MV_sel.append(('MIFS', MIFS.mifs(X, Y, n_selected_features=num_fea))) print('MIFS') MV_sel.append(('MRMR', MRMR.mrmr(X, Y, n_selected_features=num_fea))) print('MRMR') MV_sel.append(('CIFE', CIFE.cife(X, Y, n_selected_features=num_fea))) print('CIFE') MV_sel.append(('JMI', JMI.jmi(X, Y, n_selected_features=num_fea))) print('JMI') MV_sel.append(('CMIM', CMIM.cmim(X, Y, n_selected_features=num_fea))) print('CMIM') MV_sel.append(('ICAP', ICAP.icap(X, Y, n_selected_features=num_fea))) print('ICAP') MV_sel.append(('DISR', DISR.disr(X, Y, n_selected_features=num_fea))) for name, model in models: for kind, idx in MV_sel: # X_sel = X[:, idx[0:num_fea]] # X_test_ = X_test[:,idx[0:num_fea]] X_train_ = X_train[:, idx[0:num_fea]] # X_validation_ = X_validation[:, idx[0:num_fea]] # X_train, X_validation, Y_train, Y_validation = model_selection.train_test_split(X_sel, Y, test_size=validation_size, random_state=seed)
resultsdf_test_balacc.boxplot() plt.ylim([0, 1]) plt.title("SVC, Test balanced accuracy") plt.xlabel("Class") plt.ylabel("Balanced accuracy") plt.savefig("/media/yannick/MANAGE/BraTS20/results/svc_cing_test_balacc.png") plt.show() # CIFE X_inp = cind_filtered.drop(columns=["ID", "Survival_days"]) y_inp = cind_filtered["Survival_days"] # normalize # X_inp_norm = selidx, selscore, _ = CIFE.cife(X_inp.values, y_inp.values, n_selected_features=5) selidx_mifs, selscore_mifs, _ = MIFS.mifs(X_inp.values, y_inp.values, n_selected_features=5) X_cife5 = X_inp.iloc[:, selidx] X_mifs5 = X_inp.iloc[:, selidx] clf = SVC(kernel='rbf') # scoring = ['accuracy', 'balanced_accuracy', 'average_precision', 'recall', 'f1', 'roc_auc'] scoring = ['accuracy', 'balanced_accuracy'] n_cvruns = 50 resultsdat = np.zeros((n_cvruns, 3+1)) resultsdf_train = pd.DataFrame(data=resultsdat, columns=["Run", "STS", "MTS", "LTS"]) resultsdf_train["Run"] = ["run_" + str(elem) for elem in np.arange(n_cvruns)] resultsdf_train.set_index("Run", inplace=True)
def CIFE_ours(train, test, K): idx, _, _ = CIFE.cife(train[0], train[1], n_selected_features=K) return idx[0:K]