object of type 'float' has no len()

时间:2018-02-26 17:41:34

标签: python neural-network pybrain

I am trying to implement an MLP in order to predict the next value of a quadratic equation, but I keep having the same problem when I am about to test the network, could you guys give me some light about it?

Error = object of type 'float' has no len()

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

#Preparing Data
dataset = pd.read_csv("C:\Users\gugub\Documents\projects\Cyrus\graph.data", header = None)
darray = np.array(dataset)

ds = SupervisedDataSet(1,1)

ds.addSample([0.2],[0.04])
ds.addSample([0.3],[0.09])
ds.addSample([0.4],[0.16])
ds.addSample([0.5],[0.25])
ds.addSample([0.6],[0.36])

#Buildin Network
net = buildNetwork(1,2,1, hiddenclass = TanhLayer)
trainer = BackpropTrainer(net,ds)
#Training Phase
for k in range(2000):
    print(trainer.train())
#Testing Phase
while True:
    e1 = float(raw_input("x >"))
    print(float(net.activate((e1))))

TraceBack:

Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/gugub/Documents/projects/Cyrus/backprop.py', wdir='C:/Users/gugub/Documents/projects/Cyrus')

File "C:\Users\gugub\Anaconda2\envs\Workspace\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)

File "C:\Users\gugub\Anaconda2\envs\Workspace\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/gugub/Documents/projects/Cyrus/backprop.py", line 28, in print(float(net.activate((e1))))

File "C:\Users\gugub\Anaconda2\envs\Workspace\lib\site-packages\pybrain\structure\networks\feedforward.py", line 20, in activate return super(FeedForwardNetworkComponent, self).activate(inpt)

File "C:\Users\gugub\Anaconda2\envs\Workspace\lib\site-packages\pybrain\structure\modules\module.py", line 104, in activate assert len(self.inputbuffer[self.offset]) == len(inpt), str((len(self.inputbuffer[self.offset]), len(inpt)))

TypeError: object of type 'float' has no len()

0 个答案:

没有答案