-
大小:文件类型: .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
相关资源
- DeepLabV3-Tensorflow-master
- 基于TensorFlow实现CNN文本分类实验指导
- tensorflow2.0 yolo3目标检测算法
- tensorflow制作自己的灰度图像数据集并
- anaconda下安装tensorflow(注:不同版本
- 北京大学曹健老师-人工智能实践:
- Deep Learning With Python - Jason Brownlee
- Python-自然场景文本检测PSENet的一个
- Python-高效准确的EAST文本检测器的一个
- Python-TensorFlow弱监督图像分割
- Python-基于tensorflow实现的用textcnn方法
- Python-subpixel利用Tensorflow的一个子像素
- 【官方文档】TensorFlow Python API docume
-
tensorflow画风迁移代码 st
yle transfer - 简单粗暴 TensorFlow
- [PDF] Reinforcement Learning With Open AI Tens
- tensorflow目标检测代码
- 基于Python的手写字体识别系统
- 基于Tensorflow的人脸识别源码
- python TensorFlow 官方文档中文版
- Python-在TensorFlow中实现实现图像卷积网
- tensorflow-1.9.0-cp37-cp37m-win_amd64.whl
- Faster-RCNN-TensorFlow-Python3.5-master
- 聊天机器人tensorflow
- caffe模型转化为tensorflow模型
- Python-一个非常简单的BiLSTMCRF模型用于
- Python-Tensorflow仿AlphaGo框架实现的AI围棋
- Mask R-CNN源码(TensorFlow版本)
- 基于python3 tensorflow DBN_and_RNN的实现
- tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl
评论
共有 条评论