首页 > 解决方案 > Sagemaker 回归 - ValueError:无法格式化输入

问题描述

我是 SageMaker 和 Python 的新手

我正在尝试使用 Jupyter Notebooks 在 AWS 上建立一个简单的回归模型。我正在使用 UCI 数据存储库中的鲍鱼日期。我将非常感谢一些帮助或链接来帮助我做什么。

在我尝试运行之前,一切看起来都很好:


regression_linear = sagemaker.estimator.Estimator(
    container,
    role=sagemaker.get_execution_role(),
    input_mode = "File",
    instance_count = 1,
    instance_type='ml.m4.xlarge',
    output_path=output_location,
    sagemaker_session=sess
    )

regression_linear.set_hyperparameters(
    feature_dim=8,
    epochs=16,
    wd=0.01,
    loss="absolute_loss",
    predictor_type="regressor",
    normalize_data=True,
    optimizer="adam",
    mini_batch_size=100,
    lr_scheduler_step=100,
    lr_scheduler_factor=0.99,
    lr_scheduler_minimum_lr=0.0001,
    learning_rate=0.1,
    )

from time import gmtime, strftime
job_name = "DEMO-linear-learner-abalone-regression-" + strftime("%H-%M-%S", gmtime())
print("Training job: ", job_name)

regression_linear.fit(inputs={"train": train_data}, job_name=job_name)

然后我收到以下错误:

ValueError                                Traceback (most recent call last)
<ipython-input-101-82bd2950b590> in <module>
----> 1 regression_linear.fit(inputs={"train": train_data}, job_name=job_name)
      2 
      3 # , "validation": test_data

ValueError: Cannot format input       age  sex  length  diameter  height  whole_weight  shucked_weight  \
449    18    0   0.565     0.455   0.150        0.8205          0.3650   
1080    7    1   0.430     0.335   0.120        0.3970          0.1985   
2310   13    0   0.435     0.350   0.110        0.3840          0.1430   
3790   10    0   0.650     0.505   0.175        1.2075          0.5105   
3609    9    0   0.555     0.405   0.120        0.9130          0.4585   
...   ...  ...     ...       ...     ...           ...             ...   
2145    9    0   0.415     0.325   0.115        0.3455          0.1405   
3815    8   -1   0.460     0.340   0.100        0.3860          0.1805   
3534    6   -1   0.400     0.315   0.090        0.3300          0.1510   
2217   13    0   0.515     0.415   0.130        0.7640          0.2760   
3041    9    1   0.575     0.470   0.150        0.9785          0.4505   

      vicera_weight  shell_weight  
449          0.1590        0.2600  
1080         0.0865        0.1035  
2310         0.1005        0.1250  
3790         0.2620        0.3900  
3609         0.1960        0.2065  
...             ...           ...  
2145         0.0765        0.1100  
3815         0.0875        0.0965  
3534         0.0680        0.0800  
2217         0.1960        0.2500  
3041         0.1960        0.2760  

[2923 rows x 9 columns]. Expecting one of str, TrainingInput, file_input or FileSystemInput

标签: pythonlinear-regressionamazon-sagemaker

解决方案


推荐阅读