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()
def plotPassiveAggressive(self): PlotInWindow.fig = Figure() self.labelTitle["text"] = "Passive Aggresive Algorithm" file = self.labelForFile["text"] file = ReadingFromFile.checkFile(file, "passiveAggressive") fig = PassiveAggressiveAlgorithm.passiveAggressivePlotInWindow(file) self.drawFigure(fig)
def plotLogisticRegression(self): PlotInWindow.fig = Figure() self.labelTitle["text"] = "Logistic Regression Algorithm" file = self.labelForFile["text"] file = ReadingFromFile.checkFile(file, "logistic") fig = LogisticRegression.logisticRegressionPlotInWindow(file) self.drawFigure(fig)
def plotPerceptron(self): PlotInWindow.fig = Figure() self.labelTitle["text"] = "Perceptron Algorithm" file = self.labelForFile["text"] file = ReadingFromFile.checkFile(file, "perceptron") fig = Perceptron.perceptronPlotInWindow(file) self.drawFigure(fig)
def oneVsAllPassiveAggressiveExample(file): data = ReadingFromFile.readDataFromFile(file, ',') x, t = Initializing.processData(data) # iz pocetnog skupa podataka razdvojimo podatke i labele listW, listB = trainClassifiers(data, "passiveAgressive") fig = PlotInWindow.plotLinesMulticlassOneVsAll(x, t, listW, listB) return fig
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()
def plotMulticlassOneVsAllPassiveAggressive(self): PlotInWindow.fig = Figure() self.labelTitle[ "text"] = "Multiclass One Vs ALL -Logistic Regression Algorithm" file = self.labelForFile["text"] file = ReadingFromFile.checkFile(file, "multiclassPassiveAggressive") fig = MulticlassOneVsAll.oneVsAllPassiveAggressiveExample(file) canvas = FigureCanvasTkAgg(fig, master=self.window) canvas.get_tk_widget().grid(row=5, columnspan=2) canvas.draw()
def plotAlgorithmInWindow(file, algorithm): data = ReadingFromFile.readDataFromFile(file, ',') # Podaci ucitani iz fajla trainingSet, testSet = CrossValidation.makeSets(data) x, t = Initializing.processData(trainingSet) t = Initializing.checkLabels(t, algorithm) kTrainingSets, kValidSets = CrossValidation.kCrossValidationMakeSets(trainingSet, 5) # Napravimo k trening i test set-ova unakrsnom validacijom (k = 5) if algorithm == "perceptron": w, b = Initializing.initialParam(x) w, b = Perceptron.train(x, t, w, b) elif algorithm == "logistic": w, b = LogisticRegression.crossTrain(kTrainingSets,kValidSets) # Istreniramo k trening setova i kao rezultat vratimo najbolje w i najbolje b (ono w i b za koje je greska bila najmanja) else: c = PassiveAggressiveAlgorithm.optC(kTrainingSets, kValidSets) # Podesimo optimalni parametar c 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) xTest, tTest = Initializing.processData(testSet) fig = PlotInWindow.plotInWindow(xTest, w, b, tTest) return fig