首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >输出用于训练一个base_estimator的每个BaggingClassifier的实例子集

输出用于训练一个base_estimator的每个BaggingClassifier的实例子集
EN

Stack Overflow用户
提问于 2015-05-15 17:19:33
回答 1查看 64关注 0票数 0

我使用带有BaggingClassifier的决策桩对某些数据进行分类:

代码语言:javascript
复制
def fit_ensemble(attributes,class_val,n_estimators):

    # max depth is 1
    decisionStump = DecisionTreeClassifier(criterion = 'entropy', max_depth = 1)

    ensemble = BaggingClassifier(base_estimator = decisionStump, n_estimators = n_estimators, verbose = 3)
    return ensemble.fit(attributes,class_val)

def predict_all(fitted_classifier, instances):
    for i, instance in enumerate(instances):
        instances[i] = fitted_classifier.predict([instances[i]])
    return list(itertools.chain(*instances))

def main(filename, n_estimators):

    df_ = read_csv(filename)

    col_names = df_.columns.values.tolist()
    attributes = col_names[0:-1] ## 0..n-1
    class_val = col_names[-1] ## n

    fitted = fit_ensemble(df_[attributes].values, df_[class_val].values, n_estimators)
    fitted_classifiers = fitted.estimators_ # get the three decision stumps.

    compared_ = DataFrame(index = range(0,len(df_.index)), columns = range(0,n_estimators + 1))
    compared_ = compared_.fillna(0)
    compared_.ix[:,n_estimators] = df_[class_val].values

    for i, fitted_classifier in enumerate(fitted_classifiers):
        compared_.ix[:,i] =  predict_all(fitted_classifier,df_[attributes].values)

我想检查用于训练每个决策树桩的随机子集。我看过集成类和决策树类的文档,但没有找到任何属性或方法来生成训练子集。这是一个徒劳无功的任务吗?或者,在树进行训练时,是否有某种方式输出训练子集?

我对熊猫很陌生,但来自R的背景。我的代码绝对不是优化的,尽管我可以保证数据集对于我的任务非常小。谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-15 17:35:29

看来我已经回答了我自己的问题。estimators_samples_属性DecisionTreeClassifier是我想要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30265285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档