data-science - AWS sagemaker 上的模型测试“无法将字符串转换为浮点数”
问题描述
XGboost 模型在 AWS sagemaker 上训练并成功部署,但我不断收到以下错误:ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError):从模型接收到客户端错误 (415),消息“无法将字符串转换为浮点数” :“。 有什么想法吗?
Test data is as following:
size mean
269 5600.0 17.499633
103 1754.0 9.270272
160 4968.0 14.080601
40 4.0 17.500000
266 36308.0 11.421855
test_data_array = test_data.drop(['mean'], axis=1).as_matrix()
test_data_array = np.array([np.float32(x) for x in test_data_array])
xgb_predictor.content_type = 'text/csv'
xgb_predictor.serializer = csv_serializer
def predict(data, rows=32):
split_array = np.array_split(data, int(data.shape[0] / float(rows) + 1))
#print(split_array)
predictions = ''
for array in split_array:
print(array[0], type(array[0]))
predictions = ','.join([predictions, xgb_predictor.predict(array[0]).decode('utf-8')])
return np.fromstring(predictions[1:], sep=',')
predictions = predict(test_data_array)
解决方案
SageMaker XGBoost 无法处理带有标题的 csv 输入。请确保在将数据发送到端点之前删除了字符串标头。
同样对于 csv 预测,SageMaker XGBoost 假设 CSV 输入没有标签列。因此,请同时删除输入数据中的标签列。
推荐阅读
- python - 布局偏离弹出 Kivy
- c++ - 试图从 zeromq pollitem 获取套接字实例
- php - 显示注意事项:多维数组中未定义的偏移量
- reactjs - 从我的 React 应用程序中的环境变量加载值不起作用
- mysql - 如何在同一张表的新列中连接主键(id)和日期?(MySQL)
- batch-file - 为什么我的文件在进入 If Statments 时会突然关闭?
- python - 如何在脚本python3中递归地重命名子目录和文件名?
- javascript - 在 Internet Explorer 11 中获取未定义?
- wordpress - 该网站使用什么平台?
- python-3.x - 在不使用 Sklearn Pipeline 的情况下获得与 Sklearn Pipeline 相同的结果