Ejemplo n.º 1
0
def test_log_reg_accuracy(attribute_id, C):
    data_set, labels = cd.create_data(cd.test_classes, attribute_id)
    data = cd.flatten_data_set(data_set)
    filename = INPUT_LOG_REG_PATTERN % (cd.attributenames[attribute_id],
                                        str(C))

    return test_classifier(data, labels, attribute_id, filename)
def train_SVM(attribute_id):
    data, labels = cd.create_data(cd.train_classes, attribute_id)
    train_data = cd.flatten_data_set(data)

    svm = SVC(C=10., kernel='rbf', probability=True)
    svm.fit(train_data, labels)

    filename = OUTPUT_SVM_PATTERN % cd.attributenames[attribute_id]
    bz_pickle(svm, filename)
def train_logistic_regression(attribute_id, C):
    data, labels = cd.create_data(cd.train_classes, attribute_id)
    train_data = cd.flatten_data_set(data)

    logreg = LogisticRegression('l2', C=C, solver='saga')
    logreg.fit(train_data, labels)

    filename = OUTPUT_LOG_REG_PATTERN % (cd.attributenames[attribute_id],
                                         str(C))
    bz_pickle(logreg, filename)
def train_logistic_regression_CV(attribute_id):
    data, labels = cd.create_data(cd.train_classes, attribute_id)
    train_data = cd.flatten_data_set(data)

    logreg = LogisticRegressionCV(Cs=[0.01, 0.1, 1., 10., 100.],
                                  cv=5,
                                  dual=False,
                                  penalty='l2',
                                  solver='saga',
                                  refit=True)
    logreg.fit(train_data, labels)

    filename = OUTPUT_LOG_REG_CV_PATTERN % cd.attributenames[attribute_id]
    bz_pickle(logreg, filename)