我已经在GCP的AI平台(ex-ML Engine)上部署了XGBoost模型以进行预测(它作为joblib文件存储在GCS中)。但是,当我尝试对功能列表进行预测时,出现“功能不匹配”错误。

AI平台需要输入数据的特定格式:



另外,当我在JupyterLab上测试预测时,分类器的.predict方法在给我一个DataFrame时可以使用,但是如果我尝试对DataFrame的数组或单行进行预测则不起作用。

我获得的错误消息(均在AI平台和JupyterLab上)为

{
  "error": "Prediction failed: Exception during sklearn prediction:
 feature_names mismatch: [THE FEATURES LIST] ['f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f20', 'f21', 'f22', 'f23', 'f24', 'f25', 'f26', 'f27', 'f28', 'f29', 'f30', 'f31', 'f32', 'f33', 'f34', 'f35', 'f36', 'f37', 'f38', 'f39', 'f40', 'f41', 'f42', 'f43', 'f44', 'f45', 'f46', 'f47', 'f48', 'f49', 'f50', 'f51', 'f52', 'f53', 'f54', 'f55', 'f56']
\nexpected [THE FEATURES LIST BUT NOT IN THE SAME ORDER] in input data
\ntraining data did not have the following fields: f23, f14, f41, f6, f19, f35, f5, f49, f50, f18, f25, f45, f36, f21, f42, f0, f2, f37, f44, f47, f16, f22, f1, f3, f8, f53, f33, f11, f38, f48, f12, f31, f39, f27, f40, f52, f26, f29, f43, f20, f4, f10, f7, f13, f28, f9, f56, f24, f17, f32, f34, f54, f51, f15, f30, f46, f55"
}


也许我提供的输入不是预期的。但是似乎AI平台上没有其他输入选项。我寻找的是专门针对Google Cloud AI平台的解决方案。

最佳答案

我通过将版本的框架设置为XGBoost(以前是sklearn)解决了问题,并在存储桶中上传了.bst文件而不是.joblib

感谢您的帮助@ user260826 :)

关于pandas - XGBoost预测在AI平台上不起作用:“功能名称不匹配”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57266635/

10-12 19:39