欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ESN学习笔记——easyesn(3)回归案例

程序员文章站 2022-07-03 19:21:37
文章目录回归案例载入包训练集和测试集训练模型拟合预测预测结果和真实值可视化模型评价,测试集上均方误差回归案例载入包# some_file.pyimport syssys.path.insert(0, '../src/easyesn/')import matplotlib.pyplot as pltimport numpy as npfrom easyesn import RegressionESNfrom easyesn import helper as hlp训练集和测试集设置输入...

回归案例

载入包

# some_file.py
import sys
sys.path.insert(0, '../src/easyesn/')
import matplotlib.pyplot as plt
import numpy as np
from easyesn import RegressionESN
from easyesn import helper as hlp

训练集和测试集

设置输入的维度,长度

inputLength = 2000
n = 500

生成数据

x = np.empty((n, inputLength))
y = np.empty((n, 1))
domain = np.linspace(0, 4*np.pi, inputLength)
for i in range(n):
    y[i, 0] = np.random.rand()*10
    x[i] = y[i, 0]*2*np.sin(domain)

划分训练集和测试集

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)

训练模型


esn = RegressionESN(n_input=1, n_output=1, n_reservoir=50, leakingRate=0.2, regressionParameters=[1e-2], solver="lsqr")

拟合


esn.fit(x_train, y_train, transientTime=100, verbose=1)

预测

y_test_pred = esn.predict(x_test, transientTime=100, verbose=1)

预测结果和真实值可视化

plt.plot(y_test_pred, "--")
plt.plot(y_test, ":")
plt.show()

ESN学习笔记——easyesn(3)回归案例

模型评价,测试集上均方误差

print(np.mean((y_test_pred-y_test)**2))
print(np.mean(np.abs(y_test_pred-y_test)))

本文地址:https://blog.csdn.net/todingdong/article/details/111937624

相关标签: 新的神经网络