def _calculateEfficiency(self): if self.Xtrain is None: pass else: predTrain = self.computePredictions(self.Xtrain) predValid = self.computePredictions(self.Xvalid) predTest = self.computePredictions(self.Xtest) self.trainError.append( 100 - utils.calculatePredictionsEfficiency(predTrain, self.ytrain)) self.epochData.append("{:.3f}".format( self.trainError[len(self.trainError) - 1])) self.validError.append( 100 - utils.calculatePredictionsEfficiency(predValid, self.yvalid)) self.epochData[len(self.epochData) - 1] += ";" + "{:.3f}".format( self.validError[len(self.validError) - 1]) self.testError.append( 100 - utils.calculatePredictionsEfficiency(predTest, self.ytest)) self.epochData[len(self.epochData) - 1] += ";" + "{:.3f}".format( self.testError[len(self.testError) - 1])
def test(): Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMoonFile() h = 200 wd = 0.0001 K = 200 maxIter = 500 # neuralNetwork = NeuralNetwork(len(Xtrain[0]), h, utils.getClassCount(ytrain), K=10, wd=wd) neuralNetworkEfficient = NeuralNetworkEfficient( len(Xtrain[0]), h, utils.getClassCount(ytrain), K, wd=wd) # neuralNetworkEfficient._w1 = neuralNetwork._w1 # neuralNetworkEfficient._w2 = neuralNetwork._w2 # neuralNetwork.train(Xtrain, ytrain, maxIter) # predTrain = neuralNetwork.computePredictions(Xtrain) # predValid = neuralNetwork.computePredictions(Xvalid) # predTest = neuralNetwork.computePredictions(Xtest) # trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) # validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) # testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) # print( "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ # + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ # + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%") neuralNetworkEfficient.train(Xtrain, ytrain, maxIter) predTrain = neuralNetworkEfficient.computePredictions(Xtrain) predValid = neuralNetworkEfficient.computePredictions(Xvalid) predTest = neuralNetworkEfficient.computePredictions(Xtest) trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) print( "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%")
def test(): Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMoonFile() h = 200 wd = 0.0001 K = 200 maxIter = 500 # neuralNetwork = NeuralNetwork(len(Xtrain[0]), h, utils.getClassCount(ytrain), K=10, wd=wd) neuralNetworkEfficient = NeuralNetworkEfficient(len(Xtrain[0]), h, utils.getClassCount(ytrain), K, wd=wd) # neuralNetworkEfficient._w1 = neuralNetwork._w1 # neuralNetworkEfficient._w2 = neuralNetwork._w2 # neuralNetwork.train(Xtrain, ytrain, maxIter) # predTrain = neuralNetwork.computePredictions(Xtrain) # predValid = neuralNetwork.computePredictions(Xvalid) # predTest = neuralNetwork.computePredictions(Xtest) # trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) # validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) # testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) # print( "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ # + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ # + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%") neuralNetworkEfficient.train(Xtrain, ytrain, maxIter) predTrain = neuralNetworkEfficient.computePredictions(Xtrain) predValid = neuralNetworkEfficient.computePredictions(Xvalid) predTest = neuralNetworkEfficient.computePredictions(Xtest) trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) print( "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%")
def trainAndPrint(Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest, h, wd, maxIter): neuralNetwork = NeuralNetworkEfficient(len(Xtrain[0]), h, utils.getClassCount(ytrain), K=50, wd=wd) neuralNetwork.train(Xtrain, ytrain, maxIter) predTrain = neuralNetwork.computePredictions(Xtrain) predValid = neuralNetwork.computePredictions(Xvalid) predTest = neuralNetwork.computePredictions(Xtest) trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) hparams = "[h: " + str(h) + " / wd: " + str(wd) + " / " + str(maxIter) + " epoques]" title = "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%" name = "regions_decision" + str(h) + "_" + str(wd) + "_" + str(maxIter) utils.plotRegionsDescision(Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest, neuralNetwork, title, name,hparams)
def _calculateEfficiency(self): if self.Xtrain is None: pass else: predTrain = self.computePredictions(self.Xtrain) predValid = self.computePredictions(self.Xvalid) predTest = self.computePredictions(self.Xtest) self.trainError.append(100-utils.calculatePredictionsEfficiency(predTrain, self.ytrain)) self.epochData.append("{:.3f}".format(self.trainError[len(self.trainError)-1])) self.validError.append(100-utils.calculatePredictionsEfficiency(predValid, self.yvalid)) self.epochData[len(self.epochData)-1] += ";"+"{:.3f}".format(self.validError[len(self.validError)-1]) self.testError.append(100-utils.calculatePredictionsEfficiency(predTest, self.ytest)) self.epochData[len(self.epochData)-1] += ";"+"{:.3f}".format(self.testError[len(self.testError)-1])
def trainAndPrint(Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest, h, wd, maxIter): neuralNetwork = NeuralNetworkEfficient(len(Xtrain[0]), h, utils.getClassCount(ytrain), K=50, wd=wd) neuralNetwork.train(Xtrain, ytrain, maxIter) predTrain = neuralNetwork.computePredictions(Xtrain) predValid = neuralNetwork.computePredictions(Xvalid) predTest = neuralNetwork.computePredictions(Xtest) trainEfficiency = utils.calculatePredictionsEfficiency(predTrain, ytrain) validEfficiency = utils.calculatePredictionsEfficiency(predValid, yvalid) testEfficiency = utils.calculatePredictionsEfficiency(predTest, ytest) hparams = "[h: " + str(h) + " / wd: " + str(wd) + " / " + str( maxIter) + " epoques]" title = "Train Err: " + "{:.2f}".format(100 - trainEfficiency) + "%" \ + " / Valid Err: " + "{:.2f}".format(100 - validEfficiency) + "%" \ + " / Test Err: " + "{:.2f}".format(100 - testEfficiency) + "%" name = "regions_decision" + str(h) + "_" + str(wd) + "_" + str(maxIter) utils.plotRegionsDescision(Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest, neuralNetwork, title, name, hparams)