python 时间序列预测——Jordan循环神经网络

本文介绍了一种使用Python进行时间序列预测的方法,通过构建简单神经网络,具体为Jordan循环神经网络,对COE数据集进行预测分析。文章详细描述了数据预处理步骤,包括数据读取、特征选择、对数转换、归一化等,并展示了如何设定输入输出变量。此外,还介绍了神经网络的搭建过程,包括网络结构定义、权重初始化、激活函数设置、学习率设定及训练过程。

数据集

COE 下载参见 python 时间序列预测——简单神经网络

设定输入输出变量并归一化

from sklearn import preprocessing
import pandas as pd

loc= "COE.csv "
temp = pd.read_csv ( loc )
data= temp . drop ( temp . columns [ [ 0 , 1 ] ] , axis=1)

x=data.drop ( data . columns [ [ 0 , 4 ] ] , axis =1)
x=x.apply(np.log )
x=pd.concat ( [ x , data ['Open?' ] ] , axis=1)

scaler_x = preprocessing . MinMaxScaler (feature_range=(0 , 1) )
x = np .array ( x ) . reshape ( ( len ( x ) ,4 ) )
x = scaler_x . fit_transform ( x )

y=data ['COE$']
scaler_y = preprocessing . MinMaxScaler (feature_range=(0 , 1) )
y = np . array ( y ) . reshape ( ( len ( y ) , 1) )
y = np . log ( y )
y = scaler_y . fit_transform ( y )

y = y.tolist ( )
x = x.tolist ( )

JordanRecurrent

在这里插入图片描述
在这里插入图片描述

import random
from pyneurgen.neuralnet import NeuralNet
from pyneurgen.recurrent import JordanRecurrent

random . seed (2019)
model = NeuralNet ()
input_nodes = 4
hidden_nodes = 7
output_nodes = 1
existing_weight_factor = 0.9

model.init_layers (input_nodes,
    [hidden_nodes],
    output_nodes,
    JordanRecurrent(existing_weight_factor))
model. randomize_network ( )
model. layers[ 1 ] . set_activation_type('sigmoid')
model. set_learnrate(0.05)
model. set_all_inputs (x)
model. set_all_targets (y)

length = len ( x )
learn_end_point = int ( length * 0.95 )
model . set_learn_range ( 0 , learn_end_point )
model . set_test_range ( learn_end_point + 1 , length -1)
model . learn ( epochs =100 , show_epoch_results =True , random_testing = False )

mse = model. test ()
print(" test set MSE =",np.round(mse ,6))

target = np.array([ item [0][0] for item in fit1.test_targets_activations ])
pred = [ item [1][0] for item in fit1.test_targets_activations ]
# pred1 = scaler_y.inverse_transform (np.array( pred ). reshape((len(pred), 1)))  # 恢复
# pred1 = np.exp(pred1)

plt.plot(target)
plt.plot(pred)
plt.plot(target*1.05,'--g',target*0.95,'--g')
plt.legend(['target','prediction','CI'])

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颹蕭蕭

白嫖?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值