博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
神经网络股票收盘价
阅读量:3726 次
发布时间:2019-05-22

本文共 2249 字,大约阅读时间需要 7 分钟。

神经网络股票收盘价

更多干货

tf模块matplotlib的使用

import numpy as npimport matplotlib.pyplot as pltx = np.array([1,2,3,4,5,6,7,8])y = np.array([3,5,7,6,2,6,10,15])plt.plot(x,y,'r')# 折线 1 x 2 y 3 colorplt.plot(x,y,'g',lw=10)# 4 line w# 折线 饼状 柱状x = np.array([1,2,3,4,5,6,7,8])y = np.array([13,25,17,36,21,16,10,15])plt.bar(x,y,0.2,alpha=1,color='b')# 5 color 4 透明度 3 0.9plt.show()

神经网络股票收盘价

# layer1:激励函数+乘加运算import tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltdate = np.linspace(1,15,15)endPrice = np.array([2511.90,2538.26,2510.68,2591.66,2732.98,2701.69,2701.29,2678.67,2726.50,2681.50,2739.17,2715.07,2823.58,2864.90,2919.08])beginPrice = np.array([2438.71,2500.88,2534.95,2512.52,2594.04,2743.26,2697.47,2695.24,2678.23,2722.13,2674.93,2744.13,2717.46,2832.73,2877.40])print(date)plt.figure()for i in range(0,15):    # 1 柱状图    dateOne = np.zeros([2])    dateOne[0] = i;    dateOne[1] = i;    priceOne = np.zeros([2])    priceOne[0] = beginPrice[i]    priceOne[1] = endPrice[i]    if endPrice[i]>beginPrice[i]:        plt.plot(dateOne,priceOne,'r',lw=8)    else:        plt.plot(dateOne,priceOne,'g',lw=8)#plt.show()# A(15x1)*w1(1x10)+b1(1*10) = B(15x10)# B(15x10)*w2(10x1)+b2(15x1) = C(15x1)# 1 A B CdateNormal = np.zeros([15,1])priceNormal = np.zeros([15,1])#归一化for i in range(0,15):    dateNormal[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])# Bw1 = tf.Variable(tf.random_uniform([1,10],0,1))b1 = tf.Variable(tf.zeros([1,10]))wb1 = tf.matmul(x,w1)+b1layer1 = tf.nn.relu(wb1) # 激励函数# Cw2 = tf.Variable(tf.random_uniform([10,1],0,1))b2 = tf.Variable(tf.zeros([15,1]))wb2 = tf.matmul(layer1,w2)+b2layer2 = tf.nn.relu(wb2)loss = tf.reduce_mean(tf.square(y-layer2))#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:dateNormal,y:priceNormal})    #预测下    # w1w2 b1b2  A + wb -->layer2    pred = sess.run(layer2,feed_dict={x:dateNormal})    predPrice = np.zeros([15,1])    for i in range(0,15):        predPrice[i,0]=(pred*3000)[i,0]    plt.plot(date,predPrice,'b',lw=1)plt.show()

转载地址:http://qclnn.baihongyu.com/

你可能感兴趣的文章
1.JSONP解决同源限制(基础)
查看>>
02.JSONP代码优化01(实现点击触发JSONP)
查看>>
03.JSONP代码优化02(实现客户端接受函数名和服务器返回函数名不同问题)
查看>>
04.JSONP代码优化03(封装JSONP函数)
查看>>
05.JSONP代码优化04(服务器端代码优化)
查看>>
案例:使用jsonp获取腾讯天气信息
查看>>
CORS跨域资源共享
查看>>
CORS跨域资源共享(方式二)
查看>>
jQuery 中的 Ajax
查看>>
RESTful风格的API
查看>>
Vue全家桶-前端路由
查看>>
ES6模块化--babel
查看>>
webpack打包工具的使用
查看>>
Vue 脚手架
查看>>
Element-UI 的基本使用
查看>>
01微信开发者工具文件介绍
查看>>
02模板语法wx:for
查看>>
03条件渲染wx:if
查看>>
04事件的绑定
查看>>
05常用组件
查看>>