2017-12-20 10 views
0

좋은 일에 신경 그물을 훈련! 나는 훈련 Keras 파이썬 라이브러리를 사용하려면 내가 4 개 개의 입력 뉴런 1 개 출력 neuron.I을 만들고 싶어 이 내 자신을 사용할 순 신경 숫자 CSV 파일 : 여기가오류-하는 Keras 내 자신의 CSV 데이터

my_5_input_numbers.csv 
0.3,0.5,0.6,0.7,1 
0.4,0.6,0.7,0.8,0 
0.5,0.7,0.8,0.9,1 

내가 CSV를 읽고 기차 matrix.Here 당신은 단순히 입력을 엉망 코드와 오류

import numpy as np 
np.set_printoptions(threshold=np.inf) 
from keras.datasets import boston_housing 
from keras.models import Sequential 
from keras.layers import Dense 
data_common=np.genfromtxt('my_5_input_numbers.csv',delimiter=',') 
""" 
data_common=array([[ 0.3, 0.5, 0.6, 0.7, 1. ], 
     [ 0.4, 0.6, 0.7, 0.8, 0. ], 
     [ 0.5, 0.7, 0.8, 0.9, 1. ]]) 
data_common.shape=(3,5)  
""" 

X_train=data_common[:,-1]#X_train.shape=(3,4) 
y_train=data_common[0:4,-1]#y_train.shape=(3,) 
y_train=y_train.reshape(3,1) 
model = Sequential() 
model.add(Dense(128,input_dim=4,activation='relu')) 
model.add(Dense(1,activation="softmax")) 
model.compile(optimizer='adam', loss='mse', metrics=['mae']) 
# train nn 
model.fit(X_train, y_train, batch_size=200, epochs=25, validation_split=0.2, verbose=2) 
#<---Error:File "D:\NetbeansPythonProjects\testDiffrentCode\src\testKeras.py", line 16, in <module> 
# model.fit(X_train, y_train, batch_size=200, epochs=25, validation_split=0.2, verbose=2) 
#ValueError: 
#Error when checking input: 
#expected dense_1_input to have shape (None, 4) but got array with shape (3, 1) 

답변

0

입니다 수 있도록 NumPy와를 사용하는 것입니다 :

X_train=data_common[:,-1] # <--- X_train.shape was actually (3,) not (3,4). 
y_train=data_common[0:4,-1] # <--- This was wrong as well. 
y_train=y_train.reshape(3,1) 

는 NumPy와의 색인 다음, 첫 번째 열 행입니다

X_train=data_common[:,0:4] 
y_train=data_common[:,-1] 
y_train=y_train.reshape(3,1) 

을 봤는데해야한다.

+0

@ 답이 맞으면 대답을 수락하십시오 ("V"클릭). – Tay2510

+0

포럼에서 저의 평판을 씁니다. 저의 투표를받지 못했습니다. 대답은 훈련 된 나를 위해 유용했습니다. –

+0

@ 투표하기 투표에 관한 것이 아닙니다. 그것은 당신의 질문에 대한 정답으로써 대답을 "받아들이 기"위한 것입니다. "V 투표"아이콘 아래에 "V"아이콘이 있습니다. – Tay2510