示例#1
0
def initialize_svm():
    fname = 'source/config.yaml'
    with open(fname, 'r') as stream:
        yaml_file = yaml.load(stream)
        #feature_selection = yaml_file['feature_selection']
        grid_search = yaml_file['grid_search']
        #svm_cost = yaml_file['svm_cost']
        #svm_gamma = yaml_file['svm_gamma']
        csv_file = yaml_file['csv_file']

    data_frame = pd.read_csv(csv_file)
    if grid_search.lower() == "false":
        grid_search = False
    else:
        grid_search = True
    SVM = SVM_Model(data_frame, grid_search)

    return SVM
示例#2
0
        lda_m = LDA_Model(CLASS_LABELS)
        models['lda'] = Model(lda_m)

        ridge_m = Ridge_Model(CLASS_LABELS)
        models['ridge'] = Model(ridge_m)

        ridge_m_10 = Ridge_Model(CLASS_LABELS)
        ridge_m.lmbda = 10.0
        models['ridge_lmda_10'] = Model(ridge_m_10)

        ridge_m_01 = Ridge_Model(CLASS_LABELS)
        ridge_m.lmbda = 0.1
        models['ridge_lmda_01'] = Model(ridge_m_01)

        svm_m = SVM_Model(CLASS_LABELS)
        models['svm'] = Model(svm_m)

        svm_m_10 = SVM_Model(CLASS_LABELS)
        svm_m.C = 10.0
        models['svm_C_10'] = Model(svm_m_10)

        svm_m_01 = SVM_Model(CLASS_LABELS)
        svm_m.C = 0.1
        models['svm_C_01'] = Model(svm_m_01)




        #########GRID SEARCH OVER MODELS############
        highest_accuracy = 0                    # Highest validation accuracy
    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN LDA REGRESSION#####

    lda_m = LDA_Model(CLASS_LABELS)
    model = Model(lda_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN QDA REGRESSION#####

    qda_m = QDA_Model(CLASS_LABELS)
    model = Model(qda_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN SVM REGRESSION#####

    svm_m = SVM_Model(CLASS_LABELS)
    model = Model(svm_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)
def lclass():
    # Load Training Data and Labels
    X = list(np.load('little_x_train.npy'))
    Y = list(np.load('little_y_train.npy'))

    # Load Validation Data and Labels
    X_val = list(np.load('little_x_val.npy'))
    Y_val = list(np.load('little_y_val.npy'))

    CLASS_LABELS = ['apple', 'banana', 'eggplant']

    # Project Data to 200 Dimensions using CCA
    feat_dim = max(X[0].shape)
    projections = Projections(feat_dim, CLASS_LABELS)
    cca_proj, white_cov = projections.cca_projection(X, Y, k=2)

    X = projections.project(cca_proj, white_cov, X)
    X_val = projections.project(cca_proj, white_cov, X_val)

    ####RUN RIDGE REGRESSION#####
    ridge_m = Ridge_Model(CLASS_LABELS)
    model = Model(ridge_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN LDA REGRESSION#####

    lda_m = LDA_Model(CLASS_LABELS)
    model = Model(lda_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN QDA REGRESSION#####

    qda_m = QDA_Model(CLASS_LABELS)
    model = Model(qda_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN SVM REGRESSION#####

    svm_m = SVM_Model(CLASS_LABELS)
    model = Model(svm_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)

    ####RUN Logistic REGRESSION#####
    lr_m = Logistic_Model(CLASS_LABELS)
    model = Model(lr_m)

    model.train_model(X, Y)
    model.test_model(X, Y)
    model.test_model(X_val, Y_val)