我正在尝试在keras中实现虚拟多元回归神经网络。输入是12维的,而输出是2维的
我的源代码已随附
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Activation
from sklearn.pipeline import Pipeline
import numpy as np
from sklearn.model_selection import train_test_split
from keras import losses
dataframe=pd.read_csv("housing.csv", delim_whitespace=True, header=None)
dataset=dataframe.values
X=dataset[:,0:12]
Y=dataset[:,11:13]
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)
l1=Dense(12, input_dim=11, activation='relu', use_bias=False)
l2=Dense(24, activation='relu', use_bias=False)
l3=Dense(12, activation='relu', use_bias=False)
l4=Dense(2, activation='linear', use_bias=False)
model=Sequential([l1,l2,l3,l4])
print("Printing model summary \n")
print(model.summary())
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train, validation_split=0.2, epochs=10, batch_size=10)
当我尝试拟合模型时。我收到以下错误
检查输入时出错:预期density_129_input具有形状 (11,)但形状为(12,)的数组
为什么会出现此错误?
在类似的回归问题(单变量)中,我遇到了类似的错误,但是当我更改损失函数时,我就能够拟合模型。在这种情况下,无论选择哪种损失函数,我都无法拟合模型。
有帮助吗?
上的讨论