예제 #1
0
def perceptronExample(file):
    file = ReadingFromFile.checkFile(file, "perceptron")
    data = ReadingFromFile.readDataFromFile(file,
                                            ',')  # Podaci ucitani iz fajla
    trainingSet, testSet = CrossValidation.makeSets(data)

    x, t = Initializing.processData(trainingSet)
    t = Initializing.checkLabels(t, "perceptron")
    w, b = Initializing.initialParam(x)
    w, b = Perceptron.train(x, t, w, b)
    Plot.plotData(x, t)
    Plot.plotLine(x, w, b)
    plt.show()
예제 #2
0
def PassiveAggressiveAlgorithmExample(file):
    file = ReadingFromFile.checkFile(file, "passiveAggressive")
    data = ReadingFromFile.readDataFromFile(file, ',')
    trainingSet, testSet = CrossValidation.makeSets(
        data)  # Napravimo trening i test set
    kTrainingSets, kValidSets = CrossValidation.kCrossValidationMakeSets(
        trainingSet,
        5)  # Napravimo k trening i test set-ova unakrsnom validacijom (k = 5)
    c = PassiveAggressiveAlgorithm.optC(kTrainingSets, kValidSets)
    w, b = PassiveAggressiveAlgorithm.crossTrain(
        kTrainingSets, kValidSets, c
    )  # Istreniramo k trening setova i kao rezultat vratimo najbolje w i najbolje b  (ono w i b za koje je greska bila najmanja)

    x, t = Initializing.processData(
        testSet)  # Rezultat crtamo i merimo nad test skupom podataka
    t = Initializing.checkLabels(t, "passiveAggressive")
    Plot.plotData(x, t)
    Plot.plotLine(x, w, b)
    plt.show()