如何解决为什么我在 Python ML 模型中收到此错误?
我在导入数据集时没有遇到任何问题。但是,当我运行 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)
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_counts)
264 return _unpack_tuple(ret)
265
~\Anaconda3\lib\site-packages\numpy\lib\arraysetops.py in _unique1d(ar,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'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。