Exemple #1
0
def desicion_tree(k, lenData, pctTest, params, threshold):

    clear_csv()

    samples = []

    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])
    quantity_for_testing = int(lenData * pctTest)
    normalizer = Normalizer()
    data = normalizer.separate_data_2(samples, quantity_for_testing)

    decisionTree = DecisionTree(threshold)
    firstRound = cross_validation(k, decisionTree, data, lenData,
                                  "trainingFeaturesFirst",
                                  "testingFeaturesFirst", "First")

    secondRound = cross_validation(k, decisionTree, data, lenData,
                                   "trainingFeaturesSecond",
                                   "testingFeaturesSecond", "Second")

    secondWithFirst = cross_validation(k, decisionTree, data, lenData,
                                       "trainingFeaturesFirstInclude",
                                       "testingFeaturesFirstInclude", "Second")

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("DT", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)
Exemple #2
0
def kd_tree_classification(k, lenData, pctTest, params, neightboards):

    clear_csv()

    samples = []

    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])
    quantity_for_testing = int(lenData * pctTest)

    normalizer = Normalizer()
    data = normalizer.prepare_data(samples, quantity_for_testing)

    kdTree = Kd_Tree(neightboards)
    firstRound = cross_validation(k, kdTree, data, lenData, "trainingFeatures",
                                  "testingFeatures", "First")

    secondRound = cross_validation(k, kdTree, data, lenData,
                                   "trainingFeatures", "testingFeatures",
                                   "Second")

    secondWithFirst = cross_validation(k, kdTree, data, lenData,
                                       "trainingFeaturesFirstInclude",
                                       "testingFeaturesFirstInclude", "Second")

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("KD-TREE", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)
def svm_classification(
        k, lenData, pctTest, params, C=1, gamma=1, kernel="rbf"):

    clear_csv()

    samples = []

    print(params)
    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])

    quantity_for_testing = int(lenData * pctTest)

    normalizer = Normalizer()
    data = normalizer.prepare_data(samples, quantity_for_testing)

    svmClassifier = SVMClassifier(kernel, C, gamma)

    firstRound = cross_validation(
        k,
        svmClassifier,
        data,
        lenData,
        "trainingFeatures",
        "testingFeatures",
        "First"
    )

    secondRound = cross_validation(
        k,
        svmClassifier,
        data,
        lenData,
        "trainingFeatures",
        "testingFeatures",
        "Second"
    )

    secondWithFirst = cross_validation(
        k,
        svmClassifier,
        data,
        lenData,
        "trainingFeaturesFirstInclude",
        "testingFeaturesFirstInclude",
        "Second"
    )

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("SVM", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)
def kd_tree_classification(k, lenData, pctTest, params, neightboards):

    clear_csv()

    samples = []

    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])
    quantity_for_testing = int(lenData * pctTest)

    normalizer = Normalizer()
    data = normalizer.prepare_data(samples, quantity_for_testing)

    kdTree = Kd_Tree(neightboards)
    firstRound = cross_validation(
        k,
        kdTree,
        data,
        lenData,
        "trainingFeatures",
        "testingFeatures",
        "First"
    )

    secondRound = cross_validation(
        k,
        kdTree,
        data,
        lenData,
        "trainingFeatures",
        "testingFeatures",
        "Second"
    )

    secondWithFirst = cross_validation(
        k,
        kdTree,
        data,
        lenData,
        "trainingFeaturesFirstInclude",
        "testingFeaturesFirstInclude",
        "Second"
    )

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("KD-TREE", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)
def desicion_tree(k, lenData, pctTest, params, threshold):

    clear_csv()

    samples = []

    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])
    quantity_for_testing = int(lenData * pctTest)
    normalizer = Normalizer()
    data = normalizer.separate_data_2(samples, quantity_for_testing)

    decisionTree = DecisionTree(threshold)
    firstRound = cross_validation(
        k,
        decisionTree,
        data,
        lenData,
        "trainingFeaturesFirst",
        "testingFeaturesFirst",
        "First"
    )

    secondRound = cross_validation(
        k,
        decisionTree,
        data,
        lenData,
        "trainingFeaturesSecond",
        "testingFeaturesSecond",
        "Second"
    )

    secondWithFirst = cross_validation(
        k,
        decisionTree,
        data,
        lenData,
        "trainingFeaturesFirstInclude",
        "testingFeaturesFirstInclude",
        "Second"
    )

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("DT", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)
Exemple #6
0
def svm_classification(k,
                       lenData,
                       pctTest,
                       params,
                       C=1,
                       gamma=1,
                       kernel="rbf"):

    clear_csv()

    samples = []

    print(params)
    if (params[0] == "PAIS"):
        samples = generar_muestra_pais(lenData)
    else:
        samples = generar_muestra_provincia(lenData, params[1])

    quantity_for_testing = int(lenData * pctTest)

    normalizer = Normalizer()
    data = normalizer.prepare_data(samples, quantity_for_testing)

    svmClassifier = SVMClassifier(kernel, C, gamma)

    firstRound = cross_validation(k, svmClassifier, data, lenData,
                                  "trainingFeatures", "testingFeatures",
                                  "First")

    secondRound = cross_validation(k, svmClassifier, data, lenData,
                                   "trainingFeatures", "testingFeatures",
                                   "Second")

    secondWithFirst = cross_validation(k, svmClassifier, data, lenData,
                                       "trainingFeaturesFirstInclude",
                                       "testingFeaturesFirstInclude", "Second")

    normalData = normalizer.get_normal_data()
    predictions = [firstRound, secondRound, secondWithFirst]

    show_accuracy("SVM", predictions)
    make_csv(k, normalData, lenData, pctTest, predictions)