我有一个由11列组成的数据,其中一个周日是绝对的。
columns = ['Series' 'Year' 'Month' 'Day' 'Weekday' 'Number1' 'Number2' 'Number3'
'Number4' 'Number5' 'Number6']由于数据最初是作为timeseries数据提供的,所以我使用下面的方法(时间序列预测教程)来使用pycaret python包预测六个数值列的值。
然而,在模型确定和比较过程中,定义了以下功能:
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('##############################################################')我收到以下错误消息:
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. 如果你能让我知道我犯了什么错误,我将不胜感激。
发布于 2022-09-22 18:47:16
我必须在setup函数中做以下更改:
numeric_features=numerical_columns至
numeric_features=[col for col in numerical_columns if col != target_var]因为,在对目标变量的任何给定迭代中,目标不再被视为numeric_features。
https://stackoverflow.com/questions/73819192
复制相似问题