你好!我想用keraspython库来训练神经网络 我想做4个输入神经元和1个输出神经元 我自己的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
我用numpy读取csv并制作火车矩阵。这里是代码和 错误
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)
你只是把你的输入搞砸了:
应该是的
numpy的索引是先行后列。你知道吗
相关问题 更多 >
编程相关推荐