I'm using ScikitlearnRandomForestClassifier as below.
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)
.
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. you can use this link to put your labels in one-hot format. https://machinelearningmastery.com/how-to-one-hot-encode-sequence-data-in-python/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.