【发布时间】:2020-11-02 20:32:56
【问题描述】:
我是机器学习的新手,我正在努力了解如何制作模型。
我想做的事。
import tensorflow as tf
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
# this are my X and Y values
X = np.array([ [x, x+1 ] for x in range(80) ])
Y = [ x + 2 for x in range(80) ]
# The data given in this case is random but has a pridictable pattern.
# if i would use a list of [81,82,1,2]
# to predict once i fit the model it will give 83.
# I have this extra information that could be helpful for the prediction.
extra_info = [ 1, 2 ]
# What is the best way to add this extra information?
# This is the only way i konw how to add it:
X = np.array([ [x, x+1, extra_info[0], extra_info[1] ] for x in range(80) ])
这是正确的做法吗?
不会混淆模型吗?
如果extra_info 有超过 1000 个字段,这是否也是正确的?
model = keras.Sequential([
layers.Dense( 64, activation='relu', input_shape =[ 4 ] ),
layers.Dense( 64, activation='relu' ),
layers.Dense( 1 )
])
model.compile(
loss='mse',
optimizer = tf.keras.optimizers.RMSprop( 0.001 ),
metrics=['mae', 'mse']
)
history = model.fit(
X, Y, epochs=20, verbose=0,
)
print(model.predict(np.array([80,81,1,2])))
【问题讨论】:
标签: python numpy tensorflow keras