Exemple #1
0
train_dl, test_dl = data.prepare_data('heart.csv')
print('Training ', len(train_dl.dataset))
print('Test ', len(test_dl.dataset))
# print(train_dl)
xTest, yTest = [], []
for i, (inputs, targets) in enumerate(test_dl):
    xTest.append(inputs.numpy().flatten())
    yTest.append(targets.numpy().flatten())
xTrain, yTrain = [], []
for i, (inputs, targets) in enumerate(train_dl):
    xTrain.append(inputs.numpy().flatten())
    yTrain.append(targets.item())
xTrain = np.array(xTrain)
yTrain = np.array(yTrain)

# define the NN
model = nn.MLP(13)
# Train NN and save the trained model for future use.
# trainAndSaveNN(train_dl, test_dl, model)
# Load trained model.
model.load_state_dict(torch.load('trainedNN.pt'))
# test the NN
acc = nn.evaluate_model(test_dl, model)
print('NN Accuracy: %.3f' % (acc * 100.0))

# Calling first pipeline
firstPipeline(train_dl, model, xTest, yTest)
# Calling second pipeline
secondPipeline(train_dl, model, xTest, yTest)
gbtWithHardLabels(xTrain, yTrain, xTest, yTest)
Exemple #2
0
for image in train_data_set.X:
    dst = pre.eqHist(image)
    dst = pre.reshape(dst)
    reshaped_train_images.append(dst)
train_data_set.X = reshaped_train_images

reshaped_test_images = []
for image in test_data_set.X:
    dst = pre.eqHist(image)
    dst = pre.reshape(dst)
    reshaped_test_images.append(dst)
test_data_set.X = reshaped_test_images

reshaped_train_images = []
for image in train_data_set.X:
    dst = image.reshape(-1, 1)
    reshaped_train_images.append(dst)
train_data_set.X = np.asarray(reshaped_train_images)

reshaped_test_images = []
for image in test_data_set.X:
    dst = image.reshape(-1, 1)
    reshaped_test_images.append(dst)
test_data_set.X = np.asarray(reshaped_test_images)

mlp = nn.MLP("NN.dat", train_data_set, print_step=1, verbose=1)
#mlp.train(n_epochs=10, learning_rate=2, decay=1.)
#mlp.make_plot()
#
#mlp.setdataset(test_data_set)
#mlp.print_accuracy()