我有一个python脚本,它在训练集上训练RandomForestClassifier
模型(scikitlearn),然后在测试集上给出分类报告。工作完美,尽管缺乏准确性。我尝试用DummyClassifier
更改RandomForestClassifier
,并再次运行该脚本,但它一直给出这个错误AttributeError: 'list' object has no attribute 'argmax'
。此错误来自dummy.py
。虚拟模型得到了训练,但是当我调用predict()
或score()
函数时,错误不断出现。我确保使用的所有x和y都是numpy.ndarray
类型。我也去了假人.py文件,试图将列表转换为数组,但这开始抛出索引器错误,表示超出范围。最后也尝试了check_X_y
,但仍然存在相同的错误。其他人有过这个问题吗?有什么解决办法吗?
代码如下:
s= RobustScaler()
x0 = [[ro for ir, ro in enumerate(rows) if ir in xlim] for
rows in self.data1]
x0 = s.fit_transform(x0)
y0 = array([[row[ylim]] for row in self.data1]).reshape(-1,1)
xt = [[ro for ir, ro in enumerate(rows) if ir in xlim] for
rows in self.data2]
xt = s.transform(xt)
yt = array([[row[ylim]] for row in self.data2]).reshape(-1,1)
print(len(self.data2), array(x0).shape, array(y0).shape)
trainNum = int(trainPC * len(y0) / 100)
print(trainNum, len(y0))
x1, y0 = check_X_y(x0, y0)
x2, yt = check_X_y(xt, yt)
print(x1[trainNum:][:].shape,x2.shape,y0.shape,yt.shape)
self.data1.clear()
try:
classOne = joblib.load(mod_name)
except FileNotFoundError:
# classOne = RandomForestClassifier(criterion='gini', n_estimators=40, class_weight='balanced', verbose=2,)
classOne = DummyClassifier(strategy='stratified')
print("fit start")
classOne.fit(x1[:trainNum], array(y0[:trainNum][:]).reshape(-1,1))
print("fit stop")
try:
print(classOne.best_params_)
except AttributeError:
pass
try:
print(classOne.feature_importances_)
except AttributeError:
pass
gc.collect()
yp = classOne.predict(x1[trainNum:])
以下是完整的错误:
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐