多粒度级联森林(gcForest)官方库安装及使用教程(通俗易懂)

编程入门 行业动态 更新时间:2024-10-22 14:41:51

多<a href=https://www.elefans.com/category/jswz/34/1769929.html style=粒度级联森林(gcForest)官方库安装及使用教程(通俗易懂)"/>

多粒度级联森林(gcForest)官方库安装及使用教程(通俗易懂)

文章目录

  • 安装教程
  • 使用教程
  • Reference

近日文献调研过程中了解到周志华教授团队在2018年提出的多粒度级联森林模型,开拓了另一条“深度化”的道路,论文中该模型的性能较好,但可惜在本地数据集上的性能却仅仅稍好于一般的集成学习模型。尽管有一点小失望,但多粒度级联森林的算法原理还是很值得一学。在安装官方库时在网上搜索的安装教程都比较旧,经本人踩坑后做此记录。
(我的环境是conda 4.8.4,python3.7.0,实验后以下安装及使用没有问题)

安装教程

首先以管理员身份进入Anaconda Prompt,并输入conda install git指令安装git

接着调用git下载官方库,继续在Anaconda Prompt中输入git clone .git指令

进入运行目录(C:\WINDOWS\system32)中的gcForest文件夹,在此文件夹中找到lib文件夹中的gcforest文件夹,然后将该gcforest文件夹复制到Anaconda3的site-packages文件夹中(C:\WINDOWS\system32\Anaconda3\Lib\site-packages)

上面的这一步复制注意不要复制错文件夹了

最后安装该官方库的依赖包,在gcForest文件夹中的requirements.txt文档中有详细的清单如下:

argparse
joblib
keras
psutil
scikit-learn>=0.18.1
scipy
simplejson
tensorflow
xgboost

为避免报错,最好手动安装(conda install)下这些包

使用教程

import gcforest
from gcforest.gcforest import GCForest
from sklearn.externals import joblib
from sklearn.datasets import load_iris, load_digits
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

get_toy_config()函数中定义模型各项参数

def get_toy_config():config = {}ca_config = {}ca_config["random_state"] = 0ca_config["max_layers"] = 100 ##最大层数ca_config["early_stopping_rounds"] = 3 ca_config["n_classes"] = 3 ##类别数##选择级联森林的基模型ca_config["estimators"] = []ca_config["estimators"].append({"n_folds": 5, "type": "XGBClassifier", "n_estimators": 10, "max_depth": 5,"objective": "multi:softprob", "silent": True, "nthread": -1, "learning_rate": 0.1} )ca_config["estimators"].append({"n_folds": 5, "type": "RandomForestClassifier", "n_estimators": 10, "max_depth": None, "n_jobs": -1})ca_config["estimators"].append({"n_folds": 5, "type": "ExtraTreesClassifier", "n_estimators": 10, "max_depth": None, "n_jobs": -1})ca_config["estimators"].append({"n_folds": 1, "type": "LogisticRegression"})config["cascade"] = ca_configreturn config

基本应用如下

def irisFunc():iris=load_iris()X,y=iris.data,iris.target ##导入数据##划分训练、测试集X_train, X_test, y_train, y_truth = train_test_split(X,y, test_size=0.2, shuffle=True, random_state=111, stratify=y)    model = GCForest(get_toy_config()) ##构建模型model.fit_transform(X_train,y_train) ##训练y_predict=model.predict(np.array(X_test)) ##预测       joblib.dump(model,'irisModel.sav') ##保存模型print(y_predict)print("accuracy:",accuracy_score(y_truth,y_predict))

更多API的说明可到官方的GitHub上看看

同时,该官方库的源码可读性比较强,可根据自身的需要做适当改动,例如在lib/gcforest/estimators/__init__.py中加入新的基模型。

多粒度级联森林的模型结构如下:

以后有空的话精读这篇论文后再记录下学习笔记吧(ps:性能真的感觉没预想中那么好啊)CSDN上也有几篇理论分析得挺详细的(例如gcforest 深度森林原理及实现)。

Reference

【gcForest】安装;【Git】安装;【安装依赖】

kingfengji/gcForest

python实践gcForest模型对鸢尾花数据集iris进行分类

更多推荐

多粒度级联森林(gcForest)官方库安装及使用教程(通俗易懂)

本文发布于:2024-03-12 01:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1730361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:粒度   易懂   通俗   森林   级联

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!