2
我的問題是這樣的:我怎樣才能改變我的代碼,如果我想使用多個輸入數據(X的多種功能)這樣的(例子):多種功能
trainX = np.array([[1,2], [2,2] ,[3,3.23] ,[4.11,4] , [5,5.11] , [6,6] ,[7,7], [8,8.1], [9,9],[10,10]])
代碼:
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Activation
# Teach "Table 3" to the network
trainX = np.array([1, 2 ,3 ,4 , 5 , 6 ,7, 8, 9,10])
trainY = np.array([3, 6, 9, 12, 15, 18, 21, 24, 27, 30])
model = Sequential()
model.add(Dense(8, input_dim=1, activation='relu'))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, nb_epoch=1200, batch_size=2, verbose=2)
# Predict 3x20, answer = 60
dataPrediction = model.predict(np.array([4]))
print (int(dataPrediction[0][0]), '<--- Predicted number')
print ('12 <-- Correct answer \n')
輸出:
12 <--- Predicted number
12 <-- Correct answer
只要改變你的'input_dim' 2。 –