import numpy as np from matplotlib.lines import Line2D from MachineLearn.Classes import Experiment import matplotlib.pyplot as plt oExp11 = Experiment.load("Objects/EXP01_1_LP_20.gzip".format()) oExp12 = Experiment.load("Objects/EXP01_2_LP_20.gzip".format()) oExp13 = Experiment.load("Objects/EXP01_3_LP_20.gzip".format()) oExp14 = Experiment.load("Objects/EXP01_4_LP_20.gzip".format()) oExp15 = Experiment.load("Objects/EXP01_5_LP_20.gzip".format()) COLORS = ['GREEN', 'RED', 'BLUE'] MARKER = ['o', '^', "*"] base1 = np.loadtxt("Datasets/XOR.txt", delimiter=",") print(oExp11) print() print(oExp12) print() print(oExp13) print() print(oExp14) print() print(oExp15) print() def getBestTrain(exp, name): """Etapa 1: Matriz confusao e grafico para melhor treinamento.""" oDataSet = exp.experimentResults[0]
oDataSet.add_sample_of_attribute( np.array(list(np.float32(y)) + [classes[x]])) oDataSet.attributes = oDataSet.attributes.astype(float) oDataSet.normalize_data_set() for j in range(20): print(j) oData = Data(len(oDataSet.labelsNames), 31, samples=50) oData.random_training_test_by_percent( np.unique(classes, return_counts=True)[1], 0.8) perc = Layered_perceptron_Logistic(learning_rate, len(oDataSet.labelsNames)) perc.train(oDataSet.attributes[oData.Training_indexes], oDataSet.labels[oData.Training_indexes], epochs) oData.model = perc oData.confusion_matrix = np.zeros( (len(oDataSet.labelsNames), len(oDataSet.labelsNames))) for i in oData.Testing_indexes: data = np.matrix(np.hstack(([-1], oDataSet.attributes[i]))).T predicted = perc.predict(data) oData.confusion_matrix[int(oDataSet.labels[i]), predicted] += 1 print(oData) oDataSet.append(oData) oExp.add_data_set( oDataSet, description=" Experimento Dermatologia LP 20 realizaçoes.".format()) oExp.save("Objects/EXP01_4_LP_20.gzip".format()) oExp = Experiment.load("Objects/EXP01_4_LP_20.gzip".format()) print(oExp) print(oExp.experimentResults[0].sum_confusion_matrix)
import numpy as np from matplotlib.lines import Line2D from MachineLearn.Classes import Experiment import matplotlib.pyplot as plt oExp11 = Experiment.load("Objects/EXP02_1_LP_20.gzip".format()) oExp12 = Experiment.load("Objects/EXP02_2_LP_20.gzip".format()) oExp13 = Experiment.load("Objects/EXP02_3_LP_20.gzip".format()) COLORS = ['GREEN', 'RED', 'BLUE'] MARKER = ['o', '^', "*"] base1 = np.loadtxt("Datasets/artifitial1.data", delimiter=",") def imprimir_resultado(oexp, name, oData): oDataSet = oexp.experimentResults[0] print( "EXPERIMENTO " + name + " MELHOR RESULTADO MSE: ", oData.params['MSE'], ) RMSE = [] MSE = [] for i in oDataSet.dataSet: RMSE.append(i.params['RMSE']) MSE.append(i.params['MSE']) MSE = np.array(MSE) RMSE = np.array(RMSE) print("\tRMSE MEDIO ", np.mean(RMSE), "DESVIO", np.std(RMSE)) print("\tMSE MEDIO ", np.mean(MSE), "DESVIO", np.std(MSE))
oDataSet = DataSet() base = np.loadtxt("Datasets/dataset2.txt", usecols=range(2), delimiter=",") classes = np.loadtxt("Datasets/dataset2.txt", usecols=-1, delimiter=",") for x, y in enumerate(base): oDataSet.add_sample_of_attribute( np.array(list(np.float32(y)) + [classes[x]])) oDataSet.attributes = oDataSet.attributes.astype(float) # oDataSet.normalize_data_set() for j in range(20): print(j) oData = Data(2, 31, samples=50) oData.random_training_test_by_percent([600, 600], 0.8) perc = Perceptron(learning_rate) perc.train(oDataSet.attributes[oData.Training_indexes], oDataSet.labels[oData.Training_indexes], epochs) oData.model = perc oData.confusion_matrix = np.zeros((2, 2)) for i in oData.Testing_indexes: data = np.matrix(np.hstack(([-1], oDataSet.attributes[i]))).T oData.confusion_matrix[int(oDataSet.labels[i]), perc.predict(data)] += 1 oDataSet.append(oData) oExp.add_data_set( oDataSet, description=" Experimento dataset2 PS 20 realizaçoes.".format()) oExp.save("Objects/EXP02_PS_20.gzip".format()) oExp = Experiment.load("Objects/EXP02_PS_20.gzip".format()) print(oExp) print(oExp.experimentResults[0].sum_confusion_matrix)
import numpy as np from matplotlib.lines import Line2D from MachineLearn.Classes import Experiment import matplotlib.pyplot as plt oExp11 = Experiment.load("Objects/EXP01_DT1_20.gzip".format()) COLORS = ['GREEN', 'RED', 'BLUE'] base1 = np.loadtxt("Datasets/dt_1.txt", delimiter=" ") # Etapa 1 def getBestTrain(exp): """Etapa 1: Matriz confusao e grafico para melhor treinamento.""" oDataSet = exp.experimentResults[0] best = 1000000 oBestData = None for oData in oDataSet.dataSet: txAcc = oData.params['MSE'] if txAcc < best: best = txAcc oBestData = oData return oBestData oData11 = getBestTrain(oExp11) oDataSet11 = oExp11.experimentResults[0] print("EXPERIMENTO 1 MELHOR RESULTADO", oData11.params) RMSE = [] MSE = []
import numpy as np from matplotlib.lines import Line2D from MachineLearn.Classes import Experiment import matplotlib.pyplot as plt oExp11 = Experiment.load("Objects/EXP01_1_PS_20.gzip".format()) oExp12 = Experiment.load("Objects/EXP01_2_PS_20.gzip".format()) oExp13 = Experiment.load("Objects/EXP01_3_PS_20.gzip".format()) oExp2 = Experiment.load("Objects/EXP02_PS_20.gzip".format()) COLORS = ['RED', 'BLUE'] print(oExp11) print() print(oExp12) print() print(oExp13) print() print(oExp2) print() # Etapa 1 def getBestTrain(exp, name): """Etapa 1: Matriz confusao e grafico para melhor treinamento.""" oDataSet = exp.experimentResults[0] best = 0 oBestData = None for oData in oDataSet.dataSet: txAcc = oData.get_metrics()[1, -1] if txAcc > best: