Machine learning ScikitLearn从管道内的FeatureUnion提取要素名称 < P>使用SKlearn的管道模型提取并构造一个统一的特征,然后将其发送到一个随机森林分类器,而一些特征提取器可以在以后被删除或添加,考虑以下结构: model = Pipeline([ ('feature_extract', FeatureUnion([ ('feature A', extracorA()), ('feature B', ExtractorB()), ('feature C', FeatureUnion([ ('c1', C1Extractor()) ('c2', C2Extractor())])) )]), ('random_forest', RandomForestRegressor(...)))])

Machine learning ScikitLearn从管道内的FeatureUnion提取要素名称 < P>使用SKlearn的管道模型提取并构造一个统一的特征,然后将其发送到一个随机森林分类器,而一些特征提取器可以在以后被删除或添加,考虑以下结构: model = Pipeline([ ('feature_extract', FeatureUnion([ ('feature A', extracorA()), ('feature B', ExtractorB()), ('feature C', FeatureUnion([ ('c1', C1Extractor()) ('c2', C2Extractor())])) )]), ('random_forest', RandomForestRegressor(...)))]),machine-learning,scikit-learn,random-forest,data-science,sklearn-pandas,Machine Learning,Scikit Learn,Random Forest,Data Science,Sklearn Pandas,我想通过检查数据来改进随机森林的预测 feature_importances_ 随机forstressor的性质 我通过以下方式获得了该列表: model._final_estimator.feature_importances_ 现在我想动态链接feature\u importances\u索引中的列号与管道中的feature name/step 是否有首选方法在要素联合内保存/检索要素名称?如何解决此问题?要使所有内容保持动态形式,可以使用下面的函数作为单独类的转换实现,并使该类的对象成

我想通过检查数据来改进随机森林的预测

feature_importances_
随机forstressor的性质

我通过以下方式获得了该列表:

model._final_estimator.feature_importances_
现在我想动态链接feature\u importances\u索引中的列号与管道中的feature name/step


是否有首选方法在要素联合内保存/检索要素名称?如何解决此问题?

要使所有内容保持动态形式,可以使用下面的函数作为单独类的转换实现,并使该类的对象成为管道的一部分。您甚至可以更改评分参数。我认为网格搜索作为管道的一部分是您正在寻找的

def best_config(model, parameters, train_instances, judgements):
    clf = GridSearchCV(model, parameters, cv=5,
                       scoring="accuracy", verbose=5, n_jobs=4)
    clf.fit(train_instances, judgements)
    best_estimator = clf.best_estimator_

    return [str(clf.best_params_), clf.best_score_,
            best_estimator]

这有助于解决问题吗?我想知道Avi是如何实现这个答案的,还是使用了不同的方法。谢谢这似乎没有回答所问的问题