python - 随机森林不分类
问题描述
我通过在数据集上使用迁移学习获得了特征向量(图像)
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"。
推荐阅读
- php - 在 php 中重定向到带有 $tag 的页面
- express - 如何将对象从 Express 应用程序传递到 Pug 前端?
- r - dplyr 中的 exp 函数变异返回 1
- reactjs - 搜索不会改变背景色
- c# - 是否可以在抽象基类中构造派生类?
- json - 从嵌套的 json 创建数据框
- python - Python 等价于 SetConstant ( Eigen )
- node.js - 目的。
...未找到模块 - ruby-on-rails - Rails 应用程序的终端输出产生双重请求
- google-bigquery - 如何使用 BigQuery ML 显式拆分数据以进行训练和评估?