代码是实现特征筛选并用随机森林分类,上课跟着老师敲但是运行不出结果报错信息居然涉及到内存方面的东西了,顿时有点懵,和老师代码进行比对终于发现错误。。。。闲着无聊的也可以来看看上面是正确答案下面是我的代码,就当锻炼眼力了
x, y = sd.samples_generator.make_classification( n_informative=4, n_features=20, n_redundant=0,random_state=5) skb = fs.SelectKBest(fs.f_regression, k=5) rfc = se.RandomForestClassifier(n_estimators=25, max_depth=4) model = pl.Pipeline([('selector', skb), ('classifier', rfc)]) x, y = sd.samples_generator.make_classification(n_informative=4, n_features=20, n_redundant=0, random_state=5) print(x.shape, y.shape, np.unique(y)) # 特征选择器 skb = fs.SelectKBest(fs.f_regression, k=5) rfc = se.RandomForestClassifier(n_estimators=25, max_depth=4) # 创建管线名字加模型,前面的最先输出作为后面的输入 model = pl.Pipeline([('selector', skb)], [('classifier', rfc)]) model.set_params(selector__k=2,classifier__n_estimators=10) model.set_params(selector__k=2,classifier__n_esitimators=10)