Uber Ludwig:做出预测

Uber Ludwig: Issue Making Predictions

我决定再惹Uber Ludwig。我想使用学习将输入数字加 1 的 python API 制作一个简单的演示。我已经成功制作了一个模型,但是在预测时出现了问题。我是 运行 github 在 CPU TensorFlow 上的 PopOS 19.10 上的最新版本。 感谢您的帮助。

编辑:我也在 windows 上重现了这个问题。

错误如下

Traceback (most recent call last):
  File "predict.py", line 3, in <module>
    x = model.predict({"numberIn":[1]}, return_type='dict')
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/api.py", line 914, in predict
    gpu_fraction=gpu_fraction,
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/api.py", line 772, in _predict
    self.model_definition['preprocessing']
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 159, in build_data
    preprocessing_parameters
  File "/home/user/.local/lib/python3.7/site-packages/ludwig/data/preprocessing.py", line 180, in handle_missing_values
    dataset_df[feature['name']] = dataset_df[feature['name']].fillna(
AttributeError: 'list' object has no attribute 'fillna'

这是我的预测脚本

from ludwig.api import LudwigModel
model = LudwigModel.load("/home/user/Documents/ludwig-test/plus1/results/api_experiment_run_0/model")
x = model.predict({"numberIn":[1]}, return_type='dict')
#x = model.predict({"numberIn":[1]}, return_type=<class 'dict'>) I tried this with no success
print(x)

这是我的训练脚本的内容。

mydata = {"numberIn":[], "value":[]}

for x in range(10000):
    mydata["numberIn"].append(x)
    mydata["value"].append(x + 1)

from ludwig.api import LudwigModel
print("Imported Ludwig")
modelobject = LudwigModel(model_definition_file="modeldef.yaml")
stats = modelobject.train(data_dict=mydata)
modelobject.close()

modeldef.yaml

input_features:
    -
        name: numberIn
        type: numerical

output_features:
    -
        name: value
        type: numerical

解决方法:预测函数的输入参数不是位置的,在这种情况下需要指定data_dictx = modelobject.predict(data_dict=mydictionary)