首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ValueError的来源是什么?如何解决?

ValueError的来源是什么?如何解决?
EN

Stack Overflow用户
提问于 2022-09-22 18:26:03
回答 1查看 22关注 0票数 -1

我有一个由11列组成的数据,其中一个周日是绝对的。

代码语言:javascript
复制
columns = ['Series' 'Year' 'Month' 'Day' 'Weekday' 'Number1' 'Number2' 'Number3'
 'Number4' 'Number5' 'Number6']

由于数据最初是作为timeseries数据提供的,所以我使用下面的方法(时间序列预测教程)来使用pycaret python包预测六个数值列的值。

然而,在模型确定和比较过程中,定义了以下功能:

代码语言:javascript
复制
def ml_modelling(train, test) -> None:
    """This function models the given timeseries dataset

    Args:
        train (pd.DataFrame): _description_
        test (pd.DataFrame): _description_
    """
    # Now that we have done the train-test-split, we are ready to train a
    # machine learning model on the train data, score it on the test data and
    # evaluate the performance of our model. In this example, I will use
    # PyCaret; an open-source, low-code machine learning library in Python that
    # automates machine learning workflows.
    numerical_columns = list(train.select_dtypes(include=[np.number]).columns.values)
    targets = [col for col in numerical_columns if col.startswith('Number')]
    for target_var in targets:

        s = setup(data=train,
                  test_data=test,
                  target=target_var,
                  fold_strategy='timeseries',
                  numeric_features=numerical_columns,
                  fold=5,
                  transform_target=True,
                  session_id=123)

        models()

        # Now to train machine learning models, you just need to run one line
        best = compare_models(sort='MAE')
        print(f'Output from compare_models for column {target_var}: \n', best)
        print('##############################################################')

我收到以下错误消息:

代码语言:javascript
复制
Traceback (most recent call last):
  File "c:/Users/username/OneDrive/Desktop/project/main_script.py", line 64, in <module>
    main()
  File "c:/Users/username/OneDrive/Desktop/project/main_script.py", line 56, in main
    ml_modelling(train, test)
  File "c:\Users\username\OneDrive\Desktop\project\utilities.py", line 1076, in ml_modelling
    s = setup(data=train,
  File "C:\Users\username\Anaconda3\lib\site-packages\pycaret\regression.py", line 571, in setup
    return pycaret.internal.tabular.setup(
  File "C:\Users\username\Anaconda3\lib\site-packages\pycaret\internal\tabular.py", line 607, in setup        
    raise ValueError(
ValueError: Column type forced is either target column or doesn't exist in the dataset. 

如果你能让我知道我犯了什么错误,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2022-09-22 18:47:16

我必须在setup函数中做以下更改:

代码语言:javascript
复制
numeric_features=numerical_columns

代码语言:javascript
复制
numeric_features=[col for col in numerical_columns if col != target_var]

因为,在对目标变量的任何给定迭代中,目标不再被视为numeric_features

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73819192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档