【发布时间】:2019-10-05 19:07:46
【问题描述】:
我收到了这个错误。
ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (860, 11)
这些是我正在使用的以下代码。 df 具有 860x15 尺寸,因此 datX 具有 860x11 尺寸
# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
df =pd.read_excel('C:/Users/ASUS/Documents/Script/Simulation.Machine.V1/Final.xlsx', sheetname= "C0")
datX = df.drop(['C0', 'C1', 'C2', 'C3'], axis=1)
import numpy as np
datY = df['C1'] / df['C0']
datW = df['C0']**(1/2)
datZ = df['C1']
q=20
p= len(datX.columns)
from keras import backend as K
# define the keras model
model = Sequential()
model.add(Dense(q, input_dim=p, activation='tanh'))
model.add(Dense(1, activation= K.exp))
# define the keras model
offset = Sequential()
offset.add(Dense(1, input_dim=1, activation='linear'))
from keras.layers import Input
tweet_a = Input(shape=(860, 11))
tweet_b = Input(shape=(860, 1))
tweetx = model(tweet_a)
tweety = offset(tweet_b)
from keras.layers import Multiply, add
output = Multiply()([tweetx, tweety])
from keras.models import Model
modelnew = Model(inputs=[tweet_a, tweet_b], outputs=output)
modelnew.compile(optimizer='rmsprop',loss='mse',metrics=['accuracy'])
modelnew.fit([datX, datW], datY, epochs=100, batch_size=10000)
我希望输出为 1 维,输入为 11 维
【问题讨论】:
标签: python machine-learning keras neural-network