`ValueError: The least populated class in y has only 1 member, which is too few` in PyCaret

`ValueError: The least populated class in y has only 1 member, which is too few` in PyCaret

我在使用 PyCaret 时遇到问题。以前我没有任何问题。

但是当我使用 pandas 对数据进行过采样并保存它时,它就开始了。

文件是here

然后我在一个单独的笔记本上阅读文件。

import pycaret
from pycaret.utils import version
from pycaret.regression import *
from pycaret.classification import *

# Read clean data
starbucks_days = pd.read_csv('days_smote.csv')

# Drop a column
starbucks_days = starbucks_days.drop(['Unnamed: 0'], axis = 1)
starbucks_days = starbucks_days.drop(['transaction', 'offer_viewed', 'offer_received', 'offer_completed'], axis = 1)
starbucks_days = starbucks_days.drop(['label'], axis = 1)

我开始使用PyCaret

# Initialize Setup
starbucks_days1 = setup(starbucks_days, target = 'time_completed_viewed', session_id = 123, log_experiment = True, experiment_name = 'days1')

但是报错

ValueError: the least populated class in y has only 1 member, 这太少了。任何class的最小组数不能小于2.

This GitHub issue gives some hints

我检查了一些参数

type(starbucks_days)
pandas.core.frame.DataFrame

starbucks_days['time_completed_viewed'].value_counts()
6.000000      1682
12.000000     1503
18.000000     1318
24.000000     1212
174.000000    1068
          ... 
444.107530       1
226.213225       1
411.947513       1
236.001744       1
394.722944       1
Name: time_completed_viewed, Length: 3572, dtype: int64

任何提示我错过了什么?正如我所说,PyCaret 可以很好地处理简单的 csv 文件,这些文件没有被过采样。

在您的导入中,您在导入 regression 之后导入了 classification,这已经覆盖了环境中的模块。

这似乎是一个回归问题(连续值)。您不需要导入 classification.

从您的代码中删除这一行,它应该可以正常工作:

from pycaret.classification import *