RandomOverSampler 似乎不接受对数转换作为我的 y 目标变量

RandomOverSampler doesn't seem to accept log transform as my y target variable

我正在尝试对小型数据集进行随机过采样以进行线性回归。然而,似乎 scikit 学习采样 API 不适用于浮点值作为其目标变量。有办法解决吗?

这是我的 y_train 值的示例,这些值是对数转换的。

3.688879 3.828641 3.401197 3.091042 4.624973

from imblearn.over_sampling import RandomOverSampler
X_over, y_over = RandomOverSampler(random_state=42).fit_sample(X_train,y_train)
--------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-53-036424abd2bd> in <module>
      1 from imblearn.over_sampling import RandomOverSampler

~\Anaconda3\lib\site-packages\imblearn\base.py in fit_resample(self, X, y)
     73             The corresponding label of `X_resampled`.
     74         """
---> 75         check_classification_targets(y)
     76         arrays_transformer = ArraysTransformer(X, y)
     77         X, y, binarize_y = self._check_X_y(X, y)

~\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in check_classification_targets(y)
    170     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
    171                       'multilabel-indicator', 'multilabel-sequences']:
--> 172         raise ValueError("Unknown label type: %r" % y_type)
    173 
    174 

ValueError: Unknown label type: 'continuous'

重采样策略不适用于回归问题。因此,RandomOverSampler 将不接受 float 类型的目标。不过,有一些方法可以使用连续目标对数据进行重新采样。一个例子是 reg_resample 可以像下面这样使用:

from imblearn.over_sampling import RandomOverSampler
from sklearn.datasets import make_regression
from reg_resampler import resampler
import numpy as np


# Create some dummy data for demonstration
X, y = make_regression(n_features=10)
df = np.append(X, y.reshape(100, 1), axis=1)

# Initialize the resampler object and generate pseudo-classes
rs = resampler()
y_classes = rs.fit(df, target=10)

# Now resample
X_res, y_res = rs.resample(
    sampler_obj=RandomOverSampler(random_state=27),
    trainX=df,
    trainY=y_classes
)

resampler 对象将根据您的目标值生成伪 类,然后使用 imblearn 包中的经典重采样对象对您的数据进行重采样。请注意,您传递给 resampler 对象的数据应包含所有数据,包括目标。