1. 最简单的神经网络(输入层、隐层、输出层):股票价格预测--------tensorflow
import numpy as np;
import tensorflow as tf;
import matplotlib.pyplot as plt;
#输入层 A(15x1)*w1(1x10)+b1(1x10)=B(15x10)
#隐藏层 B(15x10)*w2(10x1)+b2(15x1)=C(15x1)
#输出层 C(15x1)
date=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]);
plt.figure()
for i in range(0,15):
#柱状图
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]:#red up
plt.plot(dateOne,priceOne,'r',lw=8);
else:#green down
plt.plot(dateOne, priceOne, 'g', lw=8);
#plt.show();
#数据预处理
dateNormal =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;
#输入层A=》隐藏层B
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([1,10]));
wb1=tf.matmul(x,w1)+b1;
layer1=tf.nn.relu(wb1); #激励函数
#隐藏层B=》输出层C
w2=tf.Variable(tf.random_uniform([10,1],0,1));
b2=tf.Variable(tf.zeros([15,1]));