将一个分类器用于多组功能

时间:2016-08-14 05:33:59

标签: scikit-learn classification

我最近开始使用scikit-learn学习机器学习,我有一个关于将一个分类器用于多个功能集的问题。对于我的例子,我将RandomForestClassifier用于不同的功能集。我正在使用Python 3.4.3,这是我的代码:

    forest = RandomForestClassifier(max_depth = 10, min_samples_split=2, n_estimators = 100, random_state = 1)

    forest_1 = forest.fit(X_1, y)
    forest_2 = forest.fit(X_2, y)
    forest_3 = forest.fit(X_3, y)

    print(forest_1.score(X_1, y))
    print(forest_2.score(X_2, y))
    print(forest_3.score(X_3, y))

上面的代码给了我一个错误,声明为“模型的特征数量必须与输入匹配。模型n_features为7,输入n_features为4”。我的X_1的功能数量为4,X_2的数量为7,因此我将代码更改为以下内容:

    forest_1 = RandomForestClassifier(max_depth = 10, min_samples_split=2, n_estimators = 100, random_state = 1)
    forest_2 = RandomForestClassifier(max_depth = 10, min_samples_split=2, n_estimators = 100, random_state = 1)
    forest_3 = RandomForestClassifier(max_depth = 10, min_samples_split=2, n_estimators = 100, random_state = 1)

    forest_1 = forest_1.fit(X_1, y)
    forest_2 = forest_2.fit(X_2, y)
    forest_3 = forest_3.fit(X_3, y)

    print(forest_1.score(X_1, y))
    print(forest_2.score(X_2, y))
    print(forest_3.score(X_3, y))

这很好用,但是当我所有属性都相同时,我必须创建3个单独的分类器似乎是多余的。有没有更好的方法,或者我只是坚持为不同的功能集创建不同的分类器?

0 个答案:

没有答案
相关问题