Пример #1
0
        module__n_inputs=X.shape[-1],
        module__n_hiddens=10,
        module__n_layers=1,
        optimizer=torch.optim.SGD,
        optimizer__lr=1.00,
    )

    # generate some synthetic data
    #    t = 1000; d = 5; n = 100; X = (torch.rand([n,t,d])).double(); y = (torch.randint(2,(n,1))).reshape(-1).long()
    rnn.fit(X, y)

    ### Evaluate
    pd.set_option('display.precision', 3)
    for n in range(dataset.N):
        X, y = dataset.get_single_sequence_data(n)
        yproba = rnn.forward(X)
        result_df = pd.DataFrame(y, columns=['y_true'])
        result_df['Pr(y=1)'] = yproba[:, 1]
        print("\n### Seq %d" % n)
        print(result_df.__str__())
"""

# Demonstrate the use of grid search by testing different learning
# rates while saving the best model at the end.

params = [
    {
        'lr': [10,20,30],
    },
]
Пример #2
0
        module__n_layers=1,
        optimizer=torch.optim.SGD,
        optimizer__lr=.01,
    )

    X, y = dataset.get_batch_data(batch_id=0)
    rnn.fit(X, y)

    ### Evaluate
    pd.set_option('display.precision', 3)
    proba_0 = []
    proba_1 = []
    for n in range(dataset.N):
        #print(n)
        X, y = dataset.get_single_sequence_data(n)
        yproba = float(rnn.forward(X)[:, 1])
        if y[0] == 1:
            proba_1.append(yproba)
        else:
            proba_0.append(yproba)
        #result_df = pd.DataFrame(y, columns=['y_true'])
        #result_df['Pr(y=1)'] = yproba[:,1]
        # print("\n### Seq %d" % n)
        # print(result_df.__str__())
    print(np.mean(proba_0), np.mean(proba_1))
"""

# Demonstrate the use of grid search by testing different learning
# rates while saving the best model at the end.

params = [