python - 如何使用 Python 在随机森林中投票?
问题描述
我尝试使用 Python 实现随机森林,我知道有库 sklearn 但它使用的是概率。我尝试做的是使用投票来决定班级。准确度差很多。输入类是 0 和 1。
这是我的代码
from sklearn.preprocessing import LabelEncoder
estimators = []
preditions = []
labelenc_ = LabelEncoder()
labelenc_.fit(Y_train)
classes_ = labelenc_.classes_
for i in range(5):
t = DecisionTreeClassifier(max_depth=1, criterion='entropy', max_features='log2')
idx = np.random.choice(X_train.index ,size=len(X_train), replace=True)
fitted_clf= clone(t).fit(X_train.loc[idx,:],labelenc_.transform( Y_train[idx]))
estimators.append(fitted_clf)
pool = np.asarray([clf.predict(X_test) for clf in estimators]).T
v = tmp= np.apply_along_axis(lambda x: np.argmax(np.bincount(x)) ,arr=pool,axis=1)
v = labelenc_.inverse_transform(v)
我在 sklearn 中使用 predict() 方法获得大约 0.7 的准确度,但是当我使用我的代码时,准确度在 0.5 左右,具有相同的参数
解决方案
推荐阅读
- r - 我可以在 summarise_all 中应用过滤器吗?
- ios - 呈现视图后,活动指示器仅在同一视图上显示一次
- android - 布局鼓励意外点击 - 意外启动插页式广告
- spring-boot - 将一个空的多部分文件从 angular6 发送到 springboot
- java - 在 BorderPane 中禁用按钮切换
- sql - 如何根据年份和月份进行排名?
- openlayers - Tile Size 与 OpenLayers 中的默认值保持一致,即 [256,256]
- ios - WKWebView 加载太慢
- amazon-web-services - 使用 rest 获取 aws lambda 函数列表
- python-3.x - GridSearchCV 给出不同的结果