import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
date = np.linspace(1,15,15)
priceBegin = np.array([19.59,19.51,
20.98,18.67,18.52,19,
18.64,18.2,
18.73,18.84,18.42,
18.2,18.55,
19.02,18.78])
priceEnd = np.array([19.45,19.83,
20.6,20.56,
18.69,18.56,
19.18,18.68,
18.38,18.8,
18.94,18.39,
18.16,18.7,18.68])
priceHeight = np.array([20.23,19.
9,21.97,20.56,18.93,
19.09,19.32,18.78,
19.04,19,19.37,
18.4,18.59,
19.18,19.27])
priceLow = np.array([19.33,19,20.56,
18.5,18.42
,18.51,18.54,
18.07,18.34,
18.6,18.4,18.18,
18.1,18.6,18.68])
#print(date)
dataOne = np.zeros([2])
dataPrice = np.zeros([2])
dataMaxmin = np.zeros([2])
#print(dataOne)
for i in range(0,15):
dataOne[0] = date[i]
dataOne[1] = date[i]
dataPrice[0] = priceBegin[i]
dataPrice[1] = priceEnd[i]
dataMaxmin[0] = priceHeight[i]
dataMaxmin[1] = priceLow[i]
if dataPrice[0]>=dataPrice[1]:
plt.plot(dataOne,dataPrice,lw=8,color='g')
plt.plot(dataOne,dataMaxmin,lw=1,color='g')
else:
plt.plot(dataOne,dataPrice,lw=8,color='r')
plt.plot(dataOne,dataMaxmin,lw=1,color='r')
dateNormal = np.zeros([15,1])
priceNormal = np.zeros([15,1])
for i in range(0,15):
dateNormal[i,0] = i/14
priceNormal[i,0] = priceEnd[i]/50
x = tf.placeholder(tf.float32,[None,1])
y = tf.placeholder(tf.float32,[None,1])
w1 = tf.Variable(tf.random_uniform([1,10],0,1))
b1 = tf.Variable(tf.zeros([15,10]))
wb1 = tf.matmul(x,w1)+b1
layer1 = tf.nn.relu(wb1
w2 = tf.Variable(tf.random_uniform([10,1],0,1))
b2 = tf.Variable(tf.random_uniform([15,1],0,1))
wb2 = tf.matmul(layer1,w2)+b2
layer2 = tf.nn.relu(wb2)
loss = tf.reduce_mean(tf.sqrt(tf.square(y-layer2)))
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(0,1000):
sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})
pred = sess.run(layer2,feed_dict={x:dateNormal})
predPrice = np.zeros([15,1])
for i in range(0,15):
predPrice[i,0] = (pred*50)[i,0]
plt.plot(date,predPrice,'black',lw=2)
plt.show()
06_神经网络逼近股票价格
原创wx5c808bf9b561a ©著作权
©著作权归作者所有:来自51CTO博客作者wx5c808bf9b561a的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:05_matplotlib
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
TensorFlow深度学习!构建神经网络预测股票价格!⛵
股票价格数据是一个时间序列形态的数据。所以,我们使用『循环神经网络(RNN)』对这种时序相关的数据进行建模,并将其应用在股票数据上进行预测。
深度学习 人工智能 神经网络 循环神经网络 RNN -
股票价格预测
我曾经在图书馆里看到一本书,在那本书里作者提出了一种股票预测算法,即历史与
python ico #import 元组 -
【leectode 2022.1.23】股票价格波动
给你一支股票价格的数据流。数据流中每一条记录包含一个 时间戳 和该时间点股
java 时间戳 Math java代码 -
Leetcode 901. 股票价格跨度
【代码】Leetcode 901. 股票价格跨度。
leetcode 算法 c++ 测试用例 初始化