当我在Mac终端上运行代码时,发生了以下错误:
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]
这些是我的代码:
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(损耗= 'binary_crossentropy',优化= '亚当',class_mode = “二进制”)
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()
答案 0 :(得分:0)
您是否尝试在第一层中定义输入数字: net.add(密集(3,input_shape = 10))