我使用以下代码对新数据进行了预测:
def predict(dfeval, importedModel):
colNames = dfeval.columns
dtypes = dfeval.dtypes
predictions = []
for row in dfeval.iterrows():
example = tf.train.Example()
for i in range(len(colNames)):
dtype = dtypes[i]
colName = colNames[i]
value = row[1][colName]
if dtype == "object":
value = bytes(value, "utf-8")
example.features.feature[colName].bytes_list.value.extend(
[value])
elif dtype == "float":
example.features.feature[colName].float_list.value.extend(
[value])
elif dtype == "int":
example.features.feature[colName].int64_list.value.extend(
[value])
predictions.append(
importedModel.signatures["predict"](
examples=tf.constant([example.SerializeToString()])))
return predictions
val = predict(dfeval, imported)
val
提供:
[{'predictions':<tf.Tensor:shape =(1,1),dtype = float32,numpy = array([[0.24904668]],dtype = float32)>}]]
然后我可以通过以下方式打印值:
tf.print(val)
[{'predictions':[[0.249046683]]}]
但是我想在将来的计算中使用该值,例如:
val + 300
我想要退货:
300.249046683
但是到目前为止,我还没有找到提取和使用预测的方法。
您可以这样获得:
val[0]['predictions'][0][0]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句