Python ValueError:使用Xgboost时,mat必须为numpy.ndarray类型

Python ValueError:使用Xgboost时,mat必须为numpy.ndarray类型,python,numpy,machine-learning,xgboost,Python,Numpy,Machine Learning,Xgboost,我使用Xgboost创建了一个机器学习模型,效果很好。我想使用Treelite库()在C代码中转换此模型 我已经按照上面链接中提供的文档编写了代码 当我在treelite运行时模块中输入Xgboost dfeatures时,它会给出这个错误 Traceback (most recent call last): File "treelite_model.py", line 176, in <module> predict(data) File "treelite_mod

我使用Xgboost创建了一个机器学习模型,效果很好。我想使用Treelite库()在C代码中转换此模型

我已经按照上面链接中提供的文档编写了代码

当我在treelite运行时模块中输入Xgboost dfeatures时,它会给出这个错误

Traceback (most recent call last):
  File "treelite_model.py", line 176, in <module>
    predict(data)
  File "treelite_model.py", line 157, in predict
    batch = treelite.runtime.Batch.from_npy2d(dfeatures)
  File "/Users/karim/Documents/vnev/p36_avidhrt/treelite/python/treelite/runtime/../../../runtime/native/python/treelite_runtime/predictor.py", line 117, in from_npy2d
    raise ValueError('mat must be of type numpy.ndarray')
ValueError: mat must be of type numpy.ndarray
def predict():
    data = genfromtxt('AFIB.csv', delimiter=',')
    features_noise = np.zeros((5, ))

    snr, rr_num, var, fr, fr2 = find_noise_features(data)
    features_noise[0] = snr
    features_noise[1] = rr_num
    features_noise[2] = var
    features_noise[3] = fr
    features_noise[4] = fr2
    features = extract_basic_features(data, 30000)
    features = np.hstack((features, features_noise.reshape(1, -1)))

    bst = xgb.Booster({'nthread': 4})
    bst.load_model("xgb_model.bin")
    dfeatures = xgb.DMatrix(features)
    prediction = bst.predict(dfeatures,ntree_limit=420)
    prediction = prediction.astype('int8')
    result = data_preprocess.encoder.inverse_transform(prediction)
    # print(prediction)
    # print(result)
    model = treelite.Model.from_xgboost(bst)
    toolchain = 'gcc'
    # model.export_lib(toolchain=toolchain, libpath='./afibmodel.dylib', verbose=True)
    model.export_lib(toolchain=toolchain, libpath='./afibmodel.dylib',params={'parallel_comp': 32}, verbose=True)
    predictor = treelite.runtime.Predictor('./afibmodel.dylib', verbose=True)

    # batch = treelite.runtime.Batch.from_csr(dfeatures)
    batch = treelite.runtime.Batch.from_npy2d(dfeatures)

    out_pred = predictor.predict(batch)
    print(out_pred)