0

我在导入数据集时没有遇到任何问题。但是,当我运行 SMOTE 或 RandomUnderSampler 时,我得到了错误(但是,只有在这个数据集中我遇到了这个问题而不是其他人)。我什至无法确定错误指向哪个列/字段。我需要对 SMOTE/RUS 的参数进行任何更改或调整吗?

#Smote
sm = SMOTE(random_state = 2, k_neighbors= 8) 
X_train_sm, y_train_sm = sm.fit_resample(X_train.values, y_train)

X_train_rm = X_train_sm
y_train_rm = y_train_sm

#RandomUnderSampler
rus = RandomUnderSampler(
sampling_strategy = 'auto',
random_state= 0,
replacement = True)
X_train_rus, y_train_rus = rus.fit_resample(X_train.values, y_train)

错误

Traceback (most recent call last)
<ipython-input-28-b68eb88feabe> in <module>
  5 random_state= 0,
  6 replacement = True)
 ----> 7 X_train_rus, y_train_rus = rus.fit_resample(X_train.values, y_train)
  8 
  9 X_train_rm = X_train_rus

 ~\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)
167     y : array-like
168     """
--> 169     y_type = type_of_target(y)
170     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
171                       'multilabel-indicator', 'multilabel-sequences']:

~\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in type_of_target(y)
288         return 'continuous' + suffix
289 
--> 290     if (len(np.unique(y)) > 2) or (y.ndim >= 2 and len(y[0]) > 1):
291         return 'multiclass' + suffix  # [1, 2, 3] or [[1., 2., 3]] or [[1, 2]]
292     else:

<__array_function__ internals> in unique(*args, **kwargs)

 ~\Anaconda3\lib\site-packages\numpy\lib\arraysetops.py in unique(ar, return_index, return_inverse, 
 return_counts, axis)
 261     ar = np.asanyarray(ar)
 262     if axis is None:
 --> 263         ret = _unique1d(ar, return_index, return_inverse, return_counts)
 264         return _unpack_tuple(ret)
 265 

 ~\Anaconda3\lib\site-packages\numpy\lib\arraysetops.py in _unique1d(ar, return_index, 
  return_inverse, return_counts)
  309         aux = ar[perm]
  310     else:
  --> 311         ar.sort()
  312         aux = ar
  313     mask = np.empty(aux.shape, dtype=np.bool_)
  TypeError: '<' not supported between instances of 'float' and 'str'
4

0 回答 0