model.fit(oDataSet.attributes[oData.Training_indexes], binarizer(oDataSet.labels[oData.Training_indexes]), batch_size=50, epochs=epochs, verbose=1) y_pred = model.predict( oDataSet.attributes[oData.Testing_indexes]).argmax(axis=1) y_true = oDataSet.labels[oData.Testing_indexes] print(accuracy_score(y_true, y_pred)) print(confusion_matrix(y_true, y_pred)) oData.confusion_matrix = confusion_matrix(y_true, y_pred) model.save('model.h5') myArr = None with open("model.h5", "rb") as binaryfile: myArr = bytearray(binaryfile.read()) oData.model = myArr, model.history.history['loss'] oData.params = { "k_fold": K_FOLD, "GRID_RESULT": grid_result, "GRID_VALUES_NEURON": GRID_NEURON, "GRID_VALUES_BETA": GRID_B, "LEARNING RATE": LEARNING_RATE, "EPOCHS": epochs } oDataSet.append(oData) print(oData) oExp.add_data_set( oDataSet, description=" Experimento cancer LP 20 realizaçoes.".format()) oExp.save("Objects/EXP01_5_LP_20.gzip".format())
oDataSet.labels[oData.Training_indexes[train]], epochs) y_pred = [] y_true = [] for i in test: y_pred.append(mpl.predict(oDataSet.attributes[oData.Training_indexes[i]])[0, 0]) y_true.append(oDataSet.labels[oData.Training_indexes[i]]) grid_result[g1, k_slice] = mean_squared_error(y_true, y_pred) k_slice += 1 print(grid_result) best_p = GRID[np.argmin(np.mean(grid_result, axis=1))] mpl = multi_Layered_perceptron_linear(LEARNING_RATE, (oDataSet.attributes.shape[1], best_p, 1)) mpl.train_regression(oDataSet.attributes[oData.Training_indexes], oDataSet.labels[oData.Training_indexes], epochs) y_pred = [] y_true = [] for i in oData.Testing_indexes: y_pred.append(mpl.predict(oDataSet.attributes[i])[0, 0]) y_true.append(oDataSet.labels[i]) plt.scatter(oDataSet.attributes[i], y_pred[-1], color='red') plt.scatter(oDataSet.attributes[i], y_true[-1], color='green') plt.show() oData.model = mpl oData.params = {"k_fold": K_FOLD, "GRID_RESULT": grid_result, "GRID_VALUES": GRID, "LEARNING RATE": LEARNING_RATE, "EPOCHS": epochs, "MSE": mean_squared_error(y_true, y_pred), "RMSE": np.sqrt(mean_squared_error(y_true, y_pred))} oDataSet.append(oData) oExp.add_data_set(oDataSet, description=" Experimento Artificial MLP 20 realizaçoes.".format()) oExp.save("Objects/EXP02_1_LP_20.gzip".format())
ax1 = fig.add_subplot(111) # ax2 = ax1.twiny() p = [oDataSet.attributes[0], oDataSet.attributes[-1]] res = [] for i in p: data = np.matrix(np.hstack(([-1], i))).T predict = perc.predict(data)[0, 0] res.append([i, predict]) res = np.array(res) ax1.plot(base[[0, -1]], res[:, 1]) p = [base[0], base[-1]] res = [] for i in p: predict = 2 * i + 3 res.append([i, predict]) res = np.array(res) ax1.plot(res[:, 0], res[:, 1]) plt.show() oData.params = { "MSE": ert / oData.Testing_indexes.shape[0], "RMSE": np.sqrt(ert / oData.Testing_indexes.shape[0]) } print(oData.params) oDataSet.append(oData) oExp.add_data_set(oDataSet) oExp.save("Objects/EXP01_DT1_20.gzip")