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

文章目录
近日文献调研过程中了解到周志华教授团队在2018年提出的多粒度级联森林模型 , 开拓了另一条“深度化”的道路 , 论文中该模型的性能较好 , 但可惜在本地数据集上的性能却仅仅稍好于一般的集成学习模型 。尽管有一点小失望 , 但多粒度级联森林的算法原理还是很值得一学 。在安装官方库时在网上搜索的安装教程都比较旧 , 经本人踩坑后做此记录 。
(我的环境是conda 4.8.4 , .7.0 , 实验后以下安装及使用没有问题)安装教程
首先以管理员身份进入  , 并输入condagit指令安装git
接着调用git下载官方库 , 继续在 中输入git clone 指令
进入运行目录(C:\\)中的文件夹 , 在此文件夹中找到lib文件夹中的文件夹 , 然后将该文件夹复制到的site-文件夹中(C:\\\\Lib\site-)
上面的这一步复制注意不要复制错文件夹了
最后安装该官方库的依赖包 , 在文件夹中的.txt文档中有详细的清单如下:

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

文章插图
keras
-learn>=0.18.1
scipy
为避免报错 , 最好手动安装(conda )下这些包
使用教程
import gcforestfrom gcforest.gcforest import GCForestfrom sklearn.externals import joblibfrom sklearn.datasets import load_iris, load_digitsfrom sklearn.metrics import accuracy_scorefrom sklearn.model_selection import train_test_split
在()函数中定义模型各项参数
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
gcForest  多粒度级联森林官方库安装及使用教程(通俗易懂)

文章插图
基本应用如下
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的说明可到官方的上看看
同时 , 该官方库的源码可读性比较强 , 可根据自身的需要做适当改动 , 例如在lib///.py中加入新的基模型 。
多粒度级联森林的模型结构如下:
以后有空的话精读这篇论文后再记录下学习笔记吧(ps:性能真的感觉没预想中那么好啊)CSDN上也有几篇理论分析得挺详细的(例如 深度森林原理及实现) 。
【】安装;【Git】安装;【安装依赖】
/
【gcForest多粒度级联森林官方库安装及使用教程(通俗易懂)】实践模型对鸢尾花数据集iris进行分类