scikit-learn-contrib / DESlib

A Python library for dynamic classifier and ensemble selection
BSD 3-Clause "New" or "Revised" License
479 stars 106 forks source link

Random Forest together with heterogeneous classifiers as the pool #224

Closed jayahm closed 3 years ago

jayahm commented 3 years ago

Hi,

If I include Random Forest with 100 estimators in the pool together with other heterogeneous classifiers, how much is the number of base classifiers in the total?

For example, I included SVC, NB, DT, KNN and RF:

So, the total number of base classifiers is 5 or 104?

model_svc = SVC(probability=True, gamma='auto',
model_svc = SVC(probability=True, gamma='auto',
                random_state=rng).fit(X_train, y_train)
model_bayes = GaussianNB().fit(X_train, y_train)
model_tree = DecisionTreeClassifier(random_state=rng).fit(X_train, y_train)
model_knn = KNeighborsClassifier(n_neighbors=1).fit(X_train, y_train)
model_rf = RandomForestClassifier(n_estimators=100, max_depth=5,random_state=rng)

pool_classifiers = [ model_svc, model_bayes, model_tree, model_knn, model_rf]
Menelau commented 3 years ago

The DS considers each element in the list passed as input (pool_classifiers) as a single model. So if you do like:

pool_classifiers = [ model_svc, model_bayes, model_tree, model_knn, model_rf]

In this case, the RandomForest is viewed as a single model as it is one element in the list. So the DS views as a pool of 5 models.

If you want to have a pool composed of all individual trees in the forest + the other models (SVM, KNN etc) you can do like that:

pool_classifiers = [ model_svc, model_bayes, model_tree, model_knn] + model_rf.estimators_

That will add each individual model from the RandomForest ensemble to the list pool_classifiers, creating a list of 104 models.

To summarize, the number of classifiers for the DS model is the size of the list of classifiers passed as input. So if you have any doubts you can just get the length of the list len(pool_classifiers)

jayahm commented 3 years ago

Ah, I see. Thank you very much. Now, I understand.