如何在pybrain上拟合三次方程

时间:2018-02-27 21:08:38

标签: python neural-network recurrent-neural-network pybrain

我试图在一个三次方程上拟合一个神经网络,但经过多次尝试改变隐藏层上神经元的数量并增加了一个时期的数量,我只能得到这个: enter image description here

你们可以帮帮我吗?

from pybrain.datasets import SupervisedDataSet
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import TanhLayer
from pybrain.supervised.trainers import BackpropTrainer
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#Preparing Data
dataset = pd.read_csv("C:\Users\gugub\Documents\projects\Cyrus\graph.data", header = None)
darray = np.array(dataset)
x = []
y = []
ds = SupervisedDataSet(1,1)
#Preparing True inputs and True Outputs
for i in range(43):
    e1 = darray[i,0]
    s1 = darray[i,1]
    x.append(e1)
    y.append(s1)
print(x)
print(y)
ds = SupervisedDataSet(1,1)

i = 0
for i in range(43):
    ds.addSample(x[i],y[i])
print(ds)
net = buildNetwork(ds.indim,30,ds.outdim,recurrent=True)
trainer = BackpropTrainer(net,learningrate=0.01,verbose=True)

trainer.trainOnDataset(ds,20000)
trainer.testOnData(verbose=True)

y1 = []

i = 0
for i in x:
    y1.append(net.activate(i))

plt.plot(x,y,'r')
plt.plot(x,y1,'b')
plt.show()

while True:
    e2 = int(raw_input(">"))
    s2 = [e2]
    print(net.activate(s2))

P.S图中的红线是它应该是什么,蓝色是我网络生成的功能

0 个答案:

没有答案