首页 > 解决方案 > 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)

标签: data-scienceamazon-sagemaker

解决方案


SageMaker XGBoost 无法处理带有标题的 csv 输入。请确保在将数据发送到端点之前删除了字符串标头。

同样对于 csv 预测,SageMaker XGBoost 假设 CSV 输入没有标签列。因此,请同时删除输入数据中的标签列。


推荐阅读