首页 > 解决方案 > 随机森林不分类

问题描述

我通过在数据集上使用迁移学习获得了特征向量(图像)

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) 模型无法进行预测。我能做些什么?

标签: pythonclassificationrandom-forest

解决方案


是不是你的标签中的类有偏差,所以全零的预测实际上会给你很高的准确度?在这种情况下,您可能想尝试为您的 RandomForestClassifier 设置 class_weight="balanced"。


推荐阅读