def main(): # load MATLAB data mat = scipy.io.loadmat('../data/COIL20.mat') X = mat['X'] # data y = mat['Y'] # label y = y[:, 0] n_samples, n_features = X.shape X = X.astype(float) Y = construct_label_matrix(y) # split data cv = cross_validation.KFold(n_samples, n_folds=10, shuffle=True) # evaluation n_selected_features = 100 clf = svm.LinearSVC() correct = 0 for train, test in cv: W = RFS.erfs(X[train, :], Y[train, :], gamma=0.1, verbose=True) idx = feature_ranking(W) X_selected = X[:, idx[0:n_selected_features]] clf.fit(X_selected[train, :], y[train]) y_predict = clf.predict(X_selected[test, :]) acc = accuracy_score(y[test], y_predict) print acc correct = correct + acc print 'ACC', float(correct)/10
def main(): # load data mat = scipy.io.loadmat('../data/COIL20.mat') X = mat['X'] # data X = X.astype(float) y = mat['Y'] # label y = y[:, 0] kwargs = {"metric": "euclidean", "neighbor_mode": "knn", "weight_mode": "heat_kernel", "k": 5, 't': 1} W = construct_W.construct_W(X, **kwargs) # NDFS feature selection W = NDFS.ndfs(X, W=W, n_clusters=20, verbose=False) idx = feature_ranking(W) # evaluation n_selected_features = 100 X_selected = X[:, idx[0:n_selected_features]] ari, nmi, acc = evaluation(X_selected=X_selected, n_clusters=20, y=y) print 'ARI:', ari print 'NMI:', nmi print 'ACC:', acc