这是我的程序:
tf.reset_default_graph()
X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])
y = tf.placeholder(tf.float32, [None,n_outputs])
layers = [tf.contrib.rnn.LSTMCell(num_units=n_neurons,
activation=tf.nn.leaky_relu, use_peepholes = True)
for layer in range(n_layers)]
multi_layer_cell = tf.contrib.rnn.MultiRNNCell(layers)
rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)
stacked_rnn_outputs = tf.reshape(rnn_outputs, [-1, n_neurons])
stacked_outputs = tf.layers.dense(stacked_rnn_outputs, n_outputs)
outputs = tf.reshape(stacked_outputs, [-1, n_steps, n_outputs])
outputs = outputs[:,n_steps-1,:] # keep only last output of sequence
loss = tf.reduce_mean(tf.squared_difference(outputs, y)) # loss function = mean squared error
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
training_op = optimizer.minimize(loss)
我使用以下命令将输入和输出分开:
valid_set_size_percentage = 3
test_set_size_percentage = 3
col_names = []
seq_len = 5 # choose sequence length
slice1 = slice(-1) # meaning [:-1]
slice2 = slice(None,-1)
# slice2 = slice(4,-1) # meaning [4:-1]
slice3 = slice(-1,None) # meaning [-1:]
def normalize_data(df):
cols = list(df_stock.columns.values)
min_max_scaler = sklearn.preprocessing.MinMaxScaler()
df = pd.DataFrame(min_max_scaler.fit_transform(df.values))
df.columns = cols
return df
def load_data(stock, seq_len):
global col_names
data_raw = stock.as_matrix() # convert to numpy array
col_names = stock.columns[slice2]
data = []
print(data_raw.shape)
for index in range(len(data_raw) - seq_len):
data.append(data_raw[index: index + seq_len])
data = np.array(data);
valid_set_size = int(np.round(valid_set_size_percentage/100*data.shape[0]));
test_set_size = int(np.round(test_set_size_percentage/100*data.shape[0]));
train_set_size = data.shape[0] - (valid_set_size + test_set_size);
x_train = data[:train_set_size,:-1,slice2]
y_train = data[:train_set_size,-1,slice3]
x_valid = data[train_set_size:train_set_size+valid_set_size,:-1,slice2]
y_valid = data[train_set_size:train_set_size+valid_set_size,-1,slice3]
x_test = data[train_set_size+valid_set_size:,:-1,slice2]
y_test = data[train_set_size+valid_set_size:,-1,slice3]
return [x_train, y_train, x_valid, y_valid, x_test, y_test]
df_stock = df.copy()
cols = list(df_stock.columns.values)
print('df_stock.columns.values = ', cols)
df_stock_norm = df_stock.copy()
df_stock_norm = normalize_data(df_stock_norm)
x_train, y_train, x_valid, y_valid, x_test, y_test = load_data(df_stock_norm, seq_len)
下面是上面的代码:
x_train.shape = (1874, 4, 7)
y_train.shape = (1874, 1)
Inputs = 7
Outputs = 1
x_valid.shape = (60, 4, 7)
y_valid.shape = (60, 1)
x_test.shape = (60, 4, 7)
y_test.shape = (60, 1)
Index(['input1', 'input2', 'input3', 'input4', 'input5', 'input6', 'input7'], dtype='object')
根据我想分配给培训的内容,这是正确的。输入为7,输出为一列。
以下是示例数据集: See the sample csv
但是我在培训中没有得到分类的输出,尽管我无法得到。我想知道如何根据输出值对数据进行分类。我的意思是,数据输入应作为输出序列进行训练,从而给出更多1's or 0's or -1's
,这是预期的输出。
请让我知道是否有任何混淆。但请告诉我您的建议。
我可以知道如何在Tensorboard中可视化决策树吗?