[英]classifier : axis 1 is out of bounds for array of dimension 1
I'm using ScikitlearnRandomForestClassifier as below.我正在使用 ScikitlearnRandomForestClassifier 如下。
from art.estimators.classification.scikitlearn import ScikitlearnRandomForestClassifier as SRFC
from sklearn.ensemble import RandomForestClassifier as RFC
model_rand_forest = SRFC(RFC(n_estimators=500,
max_depth=45,
criterion='entropy',
random_state=32))
model_rand_forest = model_rand_forest.fit(x_train, y_train)
I ran into the following error.我遇到了以下错误。 If needed, y_train
is a series of the size (70540,)
and x_train
is of the size (70540, 128)
.如果需要, y_train
是一系列大小(70540,)
, x_train
是大小(70540, 128)
。
error:
File "<ipython-input-18-c410427d7973>", line 1, in <module>
model_rand_forest = model_rand_forest.fit(x_train , y_train)
File "E:\Anaconda3\lib\site-packages\art\estimators\classification\classifier.py", line 71, in replacement_function
return fdict[func_name](self, *args, **kwargs)
File "E:\Anaconda3\lib\site-packages\art\estimators\classification\scikitlearn.py", line 138, in fit
y_preprocessed = np.argmax(y_preprocessed, axis=1)
File "<__array_function__ internals>", line 6, in argmax
File "E:\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 1186, in argmax
return _wrapfunc(a, 'argmax', axis=axis, out=out)
File "E:\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 61, in _wrapfunc
return bound(*args, **kwds)
AxisError: axis 1 is out of bounds for array of dimension 1
you will have to provide the labels y one-hot encoded with shape (nb_samples, nb_classes) to the ART estimators for scikit-learn models.您必须向 scikit-learn 模型的 ART 估计器提供使用形状 (nb_samples, nb_classes) 编码的标签 y。 you can use this link to put your labels in one-hot format.您可以使用此链接将您的标签置于 one-hot 格式中。 https://machinelearningmastery.com/how-to-one-hot-encode-sequence-data-in-python/ https://machinelearningmastery.com/how-to-one-hot-encode-sequence-data-in-python/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.