-1

我正在尝试对 CSV 文件中的数据应用一些基于机器学习的回归。我的专栏是:

Index(['date', 'customer_id', 'product_category', 'payment_method',
       'value [USD]', 'time_on_site', 'clicks_in_site', 'USD/[Minutes]',
       'USD/clicks_in_site'],
      dtype='object')

当我运行时:

from pycaret.regression import * 
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

exp_reg = setup(data = df, target='value [USD]', session_id=123,
             high_cardinality_features = ['product_category'],
             normalize = True,
             ignore_features = ['customer_id', 'date', 'time_on_site']
             )

我收到以下错误消息:

KeyError                                  Traceback (most recent call last)
<ipython-input-43-20eab85de0cc> in <module>()
      2              high_cardinality_features = ['product_category'],
      3              normalize = True,
----> 4              ignore_features = ['customer_id', 'date', 'time_on_site']
      5              )
      6 

5 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in drop(self, labels, errors)
   5285         if mask.any():
   5286             if errors != "ignore":
-> 5287                 raise KeyError(f"{labels[mask]} not found in axis")
   5288             indexer = indexer[~mask]
   5289         return self.delete(indexer)

KeyError: "['value [USD]'] not found in axis"
4

1 回答 1

0

我找到了解决方案。列名 ['value [USD]'] 是问题所在。重命名后,代码按预期工作。它可能与列名中的括号有关,可以解释为字典或列表,但我不确定。

于 2021-05-19T08:55:34.480 回答