예제 #1
0
def main(dataset_name, s):
    
    print 'Reading dataset: ', dataset_name
    num_class, num_feature, x_train, y_train, x_test, y_test = read_dataset(dataset_name)
    
    x = np.vstack((x_train, x_test))
    y_train.shape = (len(y_train), 1)
    y_test.shape = (len(y_test), 1)
    y = np.vstack((y_train, y_test))
    y = y[:, 0]
    # plot the first 2 dimensions
    #plot_subspace(x[:, :2], y, num_class)
    
    if s > num_feature:
        print 'The target dimension must be equal or smaller than the original dim.'
        
    eig_values, eig_vectors = FisherLDA(num_class, num_feature, x_train, y_train)
    xt = np.matrix(x) * eig_vectors[:, :s]
    plot_subspace(xt, y, num_class)
예제 #2
0
def main(dataset_name):
    print 'Reading dataset: ', dataset_name
    num_class, num_feature, x_train, y_train, x_test, y_test = read_dataset(dataset_name)
    
    # PCA
    #eig_values, eig_vectors = PCA(x_train, num_feature)
    #DR_method = 'PCA'
    
    # FisherLDA
    eig_values, eig_vectors = FisherLDA(num_class, num_feature, x_train, y_train)
    DR_method = 'FisherLDA'
    
    rng = range(5, num_feature, 5)
    rng.append(1)
    for s in [ 64]:
        # reduce the dimension of training set and test set
        x_train_dr = np.matrix(x_train) * eig_vectors[:, :s]
        x_test_dr = np.matrix(x_test) * eig_vectors[:, :s]
        
        x_train_dr = np.array(x_train_dr)
        x_test_dr = np.array(x_test_dr)
        
        
        y_pred = classify_QDF(num_class, s, x_train_dr, y_train, x_test_dr)
        classifier = 'QDF'
        print '%s and %s reports with dim: %d, accuracy: %f' % (DR_method, classifier, s, sklearn.metrics.accuracy_score(y_test, y_pred))
        
        y_pred = classify_LDF(num_class, s, x_train_dr, y_train, x_test_dr)
        classifier = 'LDF'
        print '%s and %s reports with dim: %d, accuracy: %f' % (DR_method, classifier, s, sklearn.metrics.accuracy_score(y_test, y_pred))
        
        y_pred = classify_MQDF(num_class, s, x_train_dr, y_train, x_test_dr)
        classifier = 'MQDF'
        print '%s and %s reports with dim: %d, accuracy: %f' % (DR_method, classifier, s, sklearn.metrics.accuracy_score(y_test, y_pred))
        
        print ''
예제 #3
0
    f.close()
    
    y_pred = classify(mean, sigma2, weight, x_train)
    print 'Training acc:', sklearn.metrics.accuracy_score(y_train, y_pred)
    
    y_pred = classify(mean, sigma2, weight, x_test)
    print 'Test acc:', sklearn.metrics.accuracy_score(y_test, y_pred)
    
    
    
if __name__ == '__main__':
    """ Load dataset and start to train the network
    """
    import sys
    dataset_name = sys.argv[1]
    num_hidden = int(sys.argv[2]) # number of hidden nodes
    
    print 'Reading dataset: ', dataset_name
    num_class, num_feature, x_train, y_train, x_test, y_test = read_dataset(dataset_name, scaled=True)
    
    # set a validation set to check convergence
    count = len(x_train) / 3
    # Note: the dataset has been shuffled
    x_validation = np.array(x_train[:count])
    y_validation = np.array(y_train[:count])
    
    x_train = x_train[count:]
    y_train = y_train[count:]
    
    main()