我通过对数据集(图像)使用转移学习获得了特征向量
X =
[[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]
[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]
[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]
...
[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]
[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]
[0.06381412 1.5189143 0.7007909 ... 0.22550535 0.56980544 0.07307615]]
imgs_train, imgs_test, y_train, y_test, = train_test_split(X, Y,test_size=0.33, random_state=42)
Mrfc = RandomForestClassifier(n_estimators = 1000,
bootstrap = True,
oob_score = True,
criterion = 'gini',
max_features = 'auto',
max_depth = dep,
min_samples_split = int(3000),
min_samples_leaf = int(1000),
max_leaf_nodes = None,
n_jobs=-1
)
Mrfc.fit(imgs_train,y_train)
y_predict = Mrfc.predict(imgs_train)
y_predict的输出全为零:
[0。 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ...]
Y包含标签(0或1)
该模型无法做出预测。我能做什么?
最佳答案
可能是因为标签中的类偏斜,所以对全零的预测实际上可以为您提供较高的准确性?在这种情况下,您可能要尝试为RandomForestClassifier设置class_weight =“ balanced”。
关于python - 随机森林未分类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55690370/