-
大小:文件类型: .py金币: 1下载: 0 次发布日期: 2021-06-15
- 语言: Python
- 标签: TensorFlow
资源简介
TensorFlow实现股票预测的Python代码
代码片段和文件信息
‘‘‘
Created on 16/02/2017
@author: smas255
‘‘‘
import tensorflow as tf
import numpy as np
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn import metrics
import math
from matplotlib import pyplot
# Read data from csv file
def get_data(filename):
# Read file
priceDataset=np.loadtxt(open(filename “rb“) delimiter=““ skiprows=1)
# Scale data
scaler = preprocessing.MinMaxScaler(feature_range=(0 1))
X_dataset=scaler.fit_transform(priceDataset[...0])
Y_dataset=scaler.fit_transform(priceDataset[...1])
# Split data to training and test
X_train X_test y_train y_test = train_test_split(
X_dataset Y_dataset test_size=0.3 random_state=1234)
return scalerX_train X_test y_train y_test
# Create model
def multilayer_perceptron(x weights biases):
# Hidden layer with Tanh activation
layer_1 = tf.add(tf.matmul(x weights[‘h1‘]) biases[‘b1‘])
layer_1 = tf.nn.tanh(layer_1)
# Hidden layer with Tanh activation
layer_2 = tf.add(tf.matmul(layer_1 weights[‘h2‘]) biases[‘b2‘])
layer_2 = tf.nn.tanh(layer_2)
# Output layer with linear activation
out_layer = tf.matmul(layer_2 weights[‘out‘]) + biases[‘out‘]
return out_layer
if __name__ == ‘__main__‘:
# Create training and test
scaler x_train x_test y_train y_test =get_data(‘./data/aapl.csv‘)
# Reshape data for a network with single input and output
x_train=np.reshape(x_train (-1 1))
y_train=np.reshape(y_train (-1 1))
x_test=np.reshape(x_test (-1 1))
y_test=np.reshape(y_test (-1 1))
# Get size of training
total_len = x_train.shape[0]
# Parameters
learning_rate = 0.01
training_epochs = 700
batch_size = 5
display_step = 1
# Network Parameters
n_hidden_1 = 15 # 1st layer number of features
n_hidden_2 = 7 # 2nd layer number of features
n_input = x_train.shape[1]
n_output = 1
# tf Graph input
x = tf.placeholder(“float“ [None 1])
y = tf.placeholder(“float“ [None1])
# Create weights and bias vector with constant data to be similar to Azure machine learning service
weights_1 = np.empty([n_input n_hidden_1]dtype=np.float32)
weights_2 = np.empty([n_hidden_1 n_hidden_2]dtype=np.float32)
weights_3 = np.empty([n_hidden_2 n_output]dtype=np.float32)
weights_1.fill(0.1)
weights_2.fill(0.1)
weights_3.fill(0.1)
bias_1=np.empty(n_hidden_1dtype=np.float32)
bias_2=np.empty(n_hid
- 上一篇:解压微信小程序源码python文件
- 下一篇:kNN分类器和两个-Python
相关资源
- Tensorflow实现GAN生成mnist手写数字图片
- Anaconda3-5.2.0-Windows-x86_64 .exe
- python+tensorflow的yolo实现代码
- word2vec.py
- 基于selective_search对手写数字串进行分
- pb模型文件进行前向预测亲测可用
- tensorflow样例 BP神经网络
- TensorFlow usb摄像头视频目标检测代码
- tensorflow_gpu-2.3.1-cp37-cp37m-win_amd64.whl
- python3使用tensorflow构建CNN卷积神经网络
- tensorflow糖尿病数据二分类python代码
- 神经网络-二分类问题(IMDB) Keras
- win7 32位系统下tensorflow的安装,以及在
- Tensorflow练习1对电影评论进行分类
- tensorflow手写数字识别python源码案例
- Tensorflow之CNN实现CIFAR-10图像的分类p
- cython_bbox.so
- TensorFlow实战中实现word2vec代码含中文
- opencv_tensorflow
- tensorflow2.0实现mnist手写数字识别代码
- Python-TensorFlow语义分割组件
- tensorflow_random_forest_demo.py
- Tensorflow-BiLSTM分类
- TensorFlow实现人脸识别(3)--------对人
- Python-手势识别使用在TensorFlow中卷积神
- Python+Tensorflow+CNN实现车牌识别的
- 基于TensorFlow实现的闲聊机器人
- CBAM_MNIST.py
- TensorFlow 实现 Yolo
- 基于tensorflow的遥感影像分类
评论
共有 条评论