我设计了一个神经网络模型来预测值。训练后,我想预测下一个小时的下一个未来价值,并且应该在一小时一小时后连续发生。
从csv文件导入数据。
我试图使用张量流python预测值。但是我的图形不能正确显示,也无法重新缩放。训练完神经网络后,我无法预测下一个小时的下一个未来价值。
data = pd.read_csv('data15.csv')
data=pd.DataFrame(data,columns=n
['time','g','p','c','output1','output2'])
n = data.shape[0]
p = data.shape[1]
data = data.values
train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end +1
test_end = n
data_train = data[np.arange(train_start, train_end), :]
data_test = data[np.arange(test_start, test_end), :]
scaler = MinMaxScaler(feature_range=(0, 1))
scaler.fit(data_train)
data_train = scaler.transform(data_train)
data_test = scaler.transform(data_test)
X_train = data_train[:,:-2]
y_train = data_train[:,-2]
X_test = data_test[:,:-2]
y_test = data_test[:,-2]
n_dimension = X_train.shape[1]
n_neurons_1 = 512
n_neurons_2 = 512
n_samples = (len(X_train))
net = tf.InteractiveSession()
X = tf.placeholder('float', shape=[None, n_dimension])
y = tf.placeholder('float', shape=[None])
softmax = 2
weight_initializer = tf.variance_scaling_initializer(mode="fan_avg",distribution="uniform", scale=softmax) [
bias_initializer = tf.zeros_initializer()
W_hidden_1 = tf.Variable(weight_initializer([n_dimension, n_neurons_1]))
bias_hidden_1 = tf.Variable(bias_initializer([n_neurons_1]))
W_hidden_2 = tf.Variable(weight_initializer([n_neurons_1, n_neurons_2]))
bias_hidden_2 = tf.Variable(bias_initializer([n_neurons_2]))
W_out = tf.Variable(weight_initializer([n_neurons_2,2]))
bias_out = tf.Variable(bias_initializer([1]))
hidden_1 = tf.nn.relu(tf.add(tf.matmul(X, W_hidden_1), bias_hidden_1))
hidden_2 = tf.nn.relu(tf.add(tf.matmul(hidden_1, W_hidden_2), bias_hidden_2))
out = tf.transpose(tf.add(tf.matmul(hidden_2, W_out), bias_out))
mse = tf.reduce_mean(tf.squared_difference(out, y))
opt = tf.train.AdamOptimizer().minimize(mse)
net.run(tf.global_variables_initializer())
batch_size = 2
mse_train = []
mse_test = []
epochs = 10
for e in range(epochs):
shuffle_indices = np.random.permutation(np.arange(len(y_train)))
X_train = X_train[shuffle_indices]
y_train = y_train[shuffle_indices]
# Minibatch training
for i in range(0, len(y_train) // batch_size):
start = i * batch_size
batch_x = X_train[start:start + batch_size]
batch_y = y_train[start:start + batch_size]
# Run optimizer with batch
net.run(opt, feed_dict={X: batch_x, y: batch_y})
for i in range(0, len(data) // batch_size):
start = i * batch_size
batch_x = data[start:start + batch_size]
#pred = net.run(out, feed_dict={X: batch_x})
pred = net.run(out, feed_dict={X: X_test})
print(pred)
results are :-
[[-0.00037559 0.00687979 -0.00690686]
[-0.04072511 0.01665774 0.00286875]]
我缩放结果。但我也想将其缩放为原始值。