You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amazon SageMaker Python SDK输入数据格式问题求助

Amazon SageMaker Scikit-learn Estimator 输入数据格式说明
  • 核心格式要求
    你使用的Scikit-learn estimator对CSV数据有明确规则:

    • 目标变量必须放在最后一列,而非首列——这是触发Algorithm Error的关键原因
    • 若CSV包含表头,必须在训练配置中声明;无表头则无需额外设置
    • 所有特征和目标变量都得是数值型,字符串类型需提前完成编码处理
  • 修复步骤

    1. 调整CSV文件结构:把首列的目标变量移到最后一列
    2. 检查表头:如果你的CSV有表头,创建estimator时添加hyperparameters={'header': 'True'}参数;没有表头则跳过此步
    3. 验证数据:确保无缺失值、异常值,所有字段均为数值类型
  • 调整后的示例代码

    # 创建estimator时指定表头参数(如果CSV有表头)
    sklearn_estimator = SKLearn(
        entry_point='train.py',
        role=role,
        instance_count=1,
        instance_type='ml.m5.large',
        hyperparameters={'header': 'True'}
    )
    
    # 数据上传代码保持不变
    trainpath = sess.upload_data(
        path='revenue_train.csv', bucket=bucket,
        key_prefix='production')
    
    testpath = sess.upload_data(
        path='revenue_test.csv', bucket=bucket,
        key_prefix='production')
    
    # 启动异步训练
    sklearn_estimator.fit({'train':trainpath, 'test': testpath}, wait=False)
    
  • 额外提醒
    如果你的训练脚本(train.py)有自定义数据读取逻辑,要和上述格式匹配,比如使用pd.read_csv时要对应设置header参数。Algorithm Error也可能来自训练脚本的其他问题,但格式不匹配是最常见的触发因素。

内容的提问来源于stack exchange,提问作者Jojo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 03:48:35