python - 使用神经网络预测新观察的输出
问题描述
我已经使用 Python 的 Keras 包构建了一个神经网络。我的网络的目标是预测房价。这是我的训练数据集的样子。
Price Beds SqFt Built Garage FullBaths HalfBaths LotSqFt
485000 3 2336 2004 2 2.0 1.0 2178.0
430000 4 2106 2005 2 2.0 1.0 2178.0
445000 3 1410 1999 1 2.0 0.0 3049.0
...
假设我有一些要分析的新房子。例如,我想预测一所房子的价格
- 4张床
- 2500 平方英尺
- 建于 2001 年
- 3个全套卫浴
- 1 半浴
- 地段 3452 平方英尺
如何将这些值输入到我的网络中以接收预测价格。另外,有没有办法让网络报告某种置信度指标?
作为参考,这是我的网络目前的样子。
from keras.models import Sequential
from keras.layers import Dense
N = 16
model = Sequential([
Dense(N, activation='relu', input_shape=(7,)),
Dense(1, activation='relu'),
])
model.compile(optimizer='sgd',
loss='mse',
metrics=['mean_squared_error'])
hist = model.fit(X_train, Y_train,
batch_size=32, epochs=100,
validation_data=(X_val, Y_val))
model.evaluate(X_test, Y_test)[1]
提前致谢!!
解决方案
为此,您将要使用model.predict()
,如此处所述。
model.predict()
将一批输入作为参数x
。在您的情况下,您只有 1 个输入,因此您可以将其写为:
x = [[4, 2500, 2001, 0, 3, 1, 3452]] # Assumes 0 garages
print(model.predict(x)[0]) # Print the first (only) result
推荐阅读
- python - 如何检查*多个*形状文件的字段中的空值?
- node.js - Lambda 中的 nodeJS S3.getObject() 超时(图像有更好的选择吗?)
- c++ - clang-tidy 的 bugprone-exception-escape 在 MSVC STL 中表现异常
- java - 在 2 个不同的上下文中重用自定义休眠验证器
- jquery - 如何将变量的值传递给函数内的命令?
- reactjs - 在 number() 的 React Formik Yup 方法中,'round()' 方法不起作用
- apache-spark - org.apache.spark.sql.AnalysisException:同时保存 Spark Dataframe
- javascript - 在 FormData 中组装一个复杂的对象
- python-3.x - TensorFlow 音频特征提取过程不会运行
- unity3d - 关于 Unity 3d 地图建模(带搅拌机)