2017-06-02 70 views
0

當我跑我的Mac終端上的代碼,以下錯誤發生:的Python:`Dense`只能接受1位置參數( '單位',)

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

您是否嘗試過定義在F中的輸入數量第一層: net.add(Dense(3,input_shape = 10))

相關問題