多输出深度森林(gcForest)

萝らか妹 提交于 2020-01-28 04:16:14
from sklearn.datasets import make_classification
from GCForest import *
from sklearn.utils import shuffle
import numpy as np
X, y1 = make_classification(n_samples=10, n_features=100, n_informative=30, n_classes=3, random_state=1) # 生成分类数据集,10个样本,100个特征,30个有效特征,3种分类
y2 = shuffle(y1, random_state=1)  # 分类结果随机排序
y3 = shuffle(y1, random_state=2)  # 分类结果随机排序
Y = np.vstack((y1, y2, y3)).T  # 多种分类结果组合成
print('多输出多分类器真实输出分类:\n',Y)
n_samples, n_features = X.shape # 10,100
n_outputs = Y.shape[1] # 3个输出
n_classes = 3 # 每种输出有3种分类
print(X.shape)
forest1 = gcForest(shape_1X=100, window=2, tolerance=0.0)  # 生成随机森林多分类器
forest2 = gcForest(shape_1X=100, window=2, tolerance=0.0)  # 生成随机森林多分类器
forest3 = gcForest(shape_1X=100, window=2, tolerance=0.0)  # 生成随机森林多分类器

forest1.fit(X, Y[:, 0])
pred1 = forest1.predict(X)
forest2.fit(X, Y[:, 1])
pred2 = forest2.predict(X)
forest3.fit(X, Y[:, 2])
pred3 = forest3.predict(X)

result = np.vstack((pred1, pred2, pred3))
print(result.T)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!