예제 #1
0
from DBN import DBN
from dbn_util import *

d, l = loadDataSet("train.txt", 784)
# d=d[0:100]
# l=l[0:100]
testd, testl = loadDataSet("test.txt", 784)
# testd=testd[0:10]
# testl=testl[0:10]
testD = DBN([100, 100])
testD.trainDBN(d, l, batchsize=[200, 20], numepoch=[50, 200])
testD.Print()
r = []
for i in range(0, len(testd)):
    r.append(testD.predict(testd[i]))
print testl
c = map(lambda x: x + 1, map(argmax, r))
print c
dif = array(c) - array(testl)
print dif
rate = 0.0
for i in range(0, len(testd)):
    if dif[i] == 0:
        rate += 1
print rate / len(testd)
예제 #2
0
from DBN import DBN
from dbn_util import *

d, l = loadDataSet("train.txt", 784)
#d=d[0:100]
#l=l[0:100]
testd, testl = loadDataSet("test.txt", 784)
#testd=testd[0:10]
#testl=testl[0:10]
testD = DBN([100, 100])
testD.trainDBN(d, l, batchsize=[200, 20], numepoch=[50, 200])
testD.Print()
r = []
for i in range(0, len(testd)):
    r.append(testD.predict(testd[i]))
print testl
c = map(lambda x: x + 1, map(argmax, r))
print c
dif = array(c) - array(testl)
print dif
rate = 0.0
for i in range(0, len(testd)):
    if dif[i] == 0:
        rate += 1
print rate / len(testd)
예제 #3
0
x_train = trainset[:, :-1]
y_train = trainset[:, -1:]
x_test = testset[:, :-1]
y_test = testset[:, -1:]

print('x_train.shape:' + str(x_train.shape))
print('y_train.shape:' + str(y_train.shape))
print('x_test.shape:' + str(x_test.shape))
print('y_test.shape' + str(y_test.shape))

# Build model
dbn = DBN(hidden_units, input_length, output_length, device=device)

# Train model
dbn.pretrain(x_train, epoch=epoch_pretrain, batch_size=batch_size)
dbn.finetune(x_train, y_train, epoch_finetune, batch_size, loss_function,
             optimizer(dbn.parameters()))

# Make prediction and plot
y_predict = dbn.predict(x_test, batch_size)
y_real = scaler.inverse_transform(y_test.reshape(-1, 1)).flatten()
y_predict = scaler.inverse_transform(y_predict.reshape(-1, 1)).flatten()
plt.figure(1)
plt.plot(y_real, label='real')
plt.plot(y_predict, label='prediction')
plt.xlabel('MSE Error: {}'.format(mean_squared_error(y_real, y_predict)))
plt.legend()
plt.title('Prediction result')
plt.show()