def disr(data): rank = [] for i in range(6): X = data[i][:, :-1] Y = data[i][:, -1] F, _, _ = DISR.disr(X, Y) idx = samp(F[:-1].tolist()) rank.append(idx) R = rankaggregate(rank) return R
def disr(): before = datetime.datetime.now() result = DISR.disr(data, labels, mode="index", n_selected_features=treshold) # algoritmus ma treshold ale pri testoch ho nedosiahol a vyberal vsetky hodnoty after = datetime.datetime.now() print("DISR") print(len(result)) print("cas: " + str(after - before)) print('\n') if len(result) < len(header): transform_and_save(result, "DISR")
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 = DISR.disr(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 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,_,_ = DISR.disr(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 DISR_featureSelection(x, y): idx = DISR.disr(x, y) rank = feature_ranking(idx) return rank
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]) # X_sel = X[:, idx[0:num_fea]] X_test_ = X_test[:, idx[0:num_fea]] X_validate_ = X_validate[:, idx[0:num_fea]] X_train_ = X_train[:, 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) #kfold = model_selection.KFold(n_splits=10, random_state=seed) cv_results = model_selection.cross_val_score(model, X_train_, Y_train, cv=kfold, scoring='roc_auc')
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) # kfold = model_selection.KFold(n_splits=10, random_state=seed) # cv_results = model_selection.cross_val_score(model, X_train_, Y_train, cv=kfold) # msg = "%s %s: %f (%f)\n" % (kind, name, cv_results.mean(), cv_results.std()) # output.write(msg) model.fit(X_train_, Y_train) # predictions = model.predict(X_validation_)