Machine learning 使用keras为预测添加新功能时出错
我做了一个预测,只使用了床的数量(效果很好),现在,我想通过添加第二个输入(平方英尺)来提高房价 我添加了如下代码:Machine learning 使用keras为预测添加新功能时出错,machine-learning,keras,neural-network,Machine Learning,Keras,Neural Network,我做了一个预测,只使用了床的数量(效果很好),现在,我想通过添加第二个输入(平方英尺)来提高房价 我添加了如下代码: import tensorflow as tf import numpy as np from tensorflow import keras model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[2])]) xs = np.stack([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
import tensorflow as tf
import numpy as np
from tensorflow import keras
model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[2])])
xs = np.stack([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [100, 150, 200, 250, 300, 350]], axis=1)
ys = np.array([100000, 150000, 200000, 250000, 300000, 350000], dtype=float)
model.fit(xs, ys, epochs=100)
print(model.predict([[7.0], [400.0]])) # [7.0] number of beds / [400] square feet
但我得到的错误如下:
ValueError: Input 0 of layer sequential_57 is incompatible with the layer: expected axis -1 of input shape to have value 2 but received input with shape [None, 1]
请,需要您的支持来修复它并使其正常工作
关于,我从您的代码中更改了以下内容:
model.compile('adam','mae')
)(2,1)
,我将其更改为维度(1,2)
model=keras.Sequential([keras.layers.density(units=1,input_shape=[2]))
xs=np.stack([[1.0,2.0,3.0,4.0,5.0,6.0],[100150200250300350]],轴=1)
ys=np.数组([100000,150000,200000,250000,300000,350000],dtype=float)
model.compile('adam','mae')
模型拟合(xs,ys,epochs=100)
打印(model.predict(np.array([7.0400.0]]))#[7.0]床位数/[400]平方英尺#
非常感谢你的回答,它奏效了:),而且,我把“亚当”改成了“新加坡元”,损失更大。