Esempio n. 1
0
def main():
    data = load_dataCSV()
    
    look_back = 28
    jump=4
    
    train_data, test_data = dp.rescale_data(data)
    trainX, trainY = dp.create_dataset(train_data, look_back)
    trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
    testX, testY = dp.create_dataset(test_data, look_back)  
    
    model = mod.getModel(look_back)
    model.fit(
        trainX,
        trainY,
        batch_size=128,
        nb_epoch=300,
        validation_split=0.10)
    
    pred,perfs=mod.testModel(model,testX,testY,jump,look_back)
    
    actual_test_data=test_data[len(test_data)-len(pred):]

    
    print("\n Average Covarance between predicted and actual prices on only predicted days:")
    print(np.mean(perfs))
    
    print("\n Covarance between predicted and actual prices on all days:")    
    print(np.cov(actual_test_data,pred)[1][0])
    
    plt.figure(3)
    plt.plot(actual_test_data)
    
    plt.figure(4)
    plt.plot(pred)
    
    mod.saveModel(model,'lstm3')
Esempio n. 2
0
def main():
    data = load_dataCSV()

    look_back = 28
    jump = 4

    train_data, test_data = dp.rescale_data(data)
    trainX, trainY = dp.create_dataset(train_data, look_back)
    trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
    testX, testY = dp.create_dataset(test_data, look_back)

    savedModel = load_model('lstm3.h5')

    pred, perfs = mod.testModel(savedModel, testX, testY, jump, look_back)

    actual_test_data = test_data[len(test_data) - len(pred):]

    print(
        "\n Average Covarance between predicted and actual prices on only predicted days:"
    )
    print(np.mean(perfs))

    print("\n Covarance between predicted and actual prices on all days:")
    print(np.cov(actual_test_data, pred)[1][0])