TensorFlow之——股票预测小Demo

import tensorflow as tf
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

data = np.linspace(1,15,15)
endPrice = np.array([2500,2630,2222,2214,2013,2810,2547,1566,2700,2800,2900,3000,2100,2400,2500])
beginPrice = np.array([2438,2500,2536,2512,2569,2788,2466,2455,2655,2144,2100,2300,2577,2930,3000])

print(data)
plt.figure
for i in range(0,15):
    #zhu zhuang tu 
    dataOne = np.zeros([2])
    dataOne[0] = i;
    dataOne[1] = i;
    priceOne = np.zeros([2])
    priceOne[0] = beginPrice[i]
    priceOne[1] = endPrice[i]
    if endPrice[i] > beginPrice[i] :
        plt.plot(dataOne,priceOne,'r',lw=8)
    else:
        plt.plot(dataOne,priceOne,'g',lw=8)
    

dataNormal = np.zeros([15,1])
priceNormal = np.zeros([15,1])
for i in range(0,15):
    dataNormal[i,0] = i/14.0;
    priceNormal[i,0] = endPrice[i]/3000.0;
x = tf.placeholder(tf.float32,[None,1])
y = tf.placeholder(tf.float32,[None,1])
#B
w1 = tf.Variable(tf.random_uniform([1,10],0,1))
b1 = tf.Variable(tf.zeros([1,10]))

wb1 = tf.matmul(x,w1)+b1
layer1 = tf.nn.relu(wb1)#ji li han shu 
#C
w2 = tf.Variable(tf.random_uniform([10,1],0,1))
b2 = tf.Variable(tf.zeros([15,1]))
wb2 = tf.matmul(layer1,w2)+b2
layer2 = tf.nn.relu(wb2)

loss = tf.reduce_mean(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,10000):
        sess.run(train_step,feed_dict = {x:dataNormal,y:priceNormal})
    pred = sess.run(layer2,feed_dict = {x:dataNormal})
    predPrice = np.zeros([15,1])
    for i in range(0,15):
        predPrice[i,0] = (pred*3000)[i,0]
        
plt.plot(data,predPrice,'b',lw = 1)
plt.show()
    

相关文章

MNIST数据集可以说是深度学习的入门,但是使用模型预测单张M...
1、新建tensorflow环境(1)打开anacondaprompt,输入命令行...
这篇文章主要介绍“张量tensor是什么”,在日常操作中,相信...
tensorflow中model.fit()用法model.fit()方法用于执行训练过...
https://blog.csdn.net/To_be_little/article/details/12443...
根据身高推测体重const$=require('jquery');const...