简体   繁体   中英

Python:`Dense` can accept only 1 positional arguments ('units',)

When I ran the codes on my Mac terminal,the following errors happened:

Traceback (most recent call last):
  File "data.py", line 20, in <module>
    net.add(Dense(3,10))
  File "/Users/Superman/anaconda/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 43, in wrapper
    str(list(args[1:])))
TypeError: `Dense` can accept only 1 positional arguments ('units',), but you passed the following positional arguments: [3, 10]

These are my codes:

import pandas as pd
from random import shuffle
datafile='data.xls'
data=pd.read_excel(datafile)
data=data.as_matrix()
shuffle(data)
p=0.8
train=data[:int(len(data)*p),:]
test=data[int(len(data)*p):,:]

from keras.models import Sequential
from keras.layers.core import Dense,Activation

netfile='net.model'

net=Sequential()
net.add(Dense(3,10))
net.add(Activation('relu'))
net.add(Dense(10,1))
net.add(Activation('sigmoid'))

net.compile(loss='binary_crossentropy',optimizer='adam',class_mode="binary")

net.fit(train[:,:3],train[:,3],nb_epoch=1000,batch_size=1)
net.save_weights(netfile)

predict_result=net.predict_classes(train[:,:3]).reshape(len(train))

from cm_plot import*
cm_plot(train[:,3],predict_result).show()

您是否尝试过在第一层中定义输入数字:net.add(Dense(3,input_shape = 10))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM