如何在python中使用Orange api进行预测?

时间:2019-05-18 04:23:02

标签: python python-3.x orange-api

我是使用橙色api的新手,而且我不太了解python代码对神经网络模型的预测需要什么

    import pickle
    import Orange

    #Load model
    with open("modelNN.pkcls", "rb") as f:
      model = pickle.load(f)

    data = Orange.data.Table('test.xlsx')
    model.predict(data[0])



Expected 2D array, got 1D array instead:
array=[6.0000000e+00 2.0000000e+00 3.0000000e+00 3.0000000e+00 1.0000000e+00
 2.0000000e+00 1.7283000e+02 1.7179000e+02 6.1008990e+05 1.9051511e+06
 1.1090000e+04 3.5300000e+03].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

1 个答案:

答案 0 :(得分:0)

错误表明global接受2D数组,并且收到1D数组。如果打印nonlocal,您将看到它确实是1D。

关于预测的文档很差,但是它是这样工作的:

  • model.predict()接受2D numpy数组
  • data[0]接受Orange.data.Table

模型的model.predict()函数尝试智能地处理输入,这意味着您可以 model.predict_storage(),数据类型为__call__model(data[0])

也就是说,Orange并不是真正打算用作库。我建议通过GUI或使用其他Python库(例如sklearn)来使用它,无论如何,它都是Orange的基础。