I am trying to plug in financial data into the VI example to do a classification with it.
The data is set in the following way, that should be right because it is working with a simple Bayesian Regression with PyMC3.
df = df.reset_index()
X= (df['Close']).values
Y= (df['Close']).index.values
X.shape, Y.shape
But I get an error message, when I try to execute the code
def construct_nn(ann_input, ann_output):
n_hidden = 5
# Initialize random weights between each layer
init_1 = np.random.randn(X.shape[1], n_hidden).astype(floatX)
init_2 = np.random.randn(n_hidden, n_hidden).astype(floatX)
init_out = np.random.randn(n_hidden).astype(floatX)
with pm.Model() as neural_network:
# Trick: Turn inputs and outputs into shared variables using the data container pm.Data
# It's still the same thing, but we can later change the values of the shared variable
# (to switch in the test-data later) and pymc3 will just use the new data.
# Kind-of like a pointer we can redirect.
# For more info, see: http://deeplearning.net/software/theano/library/compile/shared.html
ann_input = pm.Data('ann_input', X)
ann_output = pm.Data('ann_output', Y)
# Weights from input to hidden layer
weights_in_1 = pm.Normal('w_in_1', 0, sigma=1,
shape=(X.shape[1], n_hidden),
testval=init_1)
# Weights from 1st to 2nd layer
weights_1_2 = pm.Normal('w_1_2', 0, sigma=1,
shape=(n_hidden, n_hidden),
testval=init_2)
# Weights from hidden layer to output
weights_2_out = pm.Normal('w_2_out', 0, sigma=1,
shape=(n_hidden,),
testval=init_out)
# Build neural-network using tanh activation function
act_1 = pm.math.tanh(pm.math.dot(ann_input,
weights_in_1))
act_2 = pm.math.tanh(pm.math.dot(act_1,
weights_1_2))
act_out = pm.math.sigmoid(pm.math.dot(act_2,
weights_2_out))
# Binary classification -> Bernoulli likelihood
out = pm.Bernoulli('out',
act_out,
observed=ann_output,
total_size=Y.shape[0] # IMPORTANT for minibatches
)
return neural_network
neural_network = construct_nn(X, Y)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [7], in <cell line: 49>()
42 out = pm.Bernoulli('out',
43 act_out,
44 observed=ann_output,
45 total_size=Y.shape[0] # IMPORTANT for minibatches
46 )
47 return neural_network
---> 49 neural_network = construct_nn(X, Y)
Input In [7], in construct_nn(ann_input, ann_output)
2 n_hidden = 5
4 # Initialize random weights between each layer
----> 5 init_1 = np.random.randn(X.shape[1], n_hidden).astype(floatX)
6 init_2 = np.random.randn(n_hidden, n_hidden).astype(floatX)
7 init_out = np.random.randn(n_hidden).astype(floatX)
IndexError: tuple index out of range
Full jupyter notebook link is here: