scikit-learn-contrib / DESlib

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

Questions relevant to KNN in the framework. #279

Closed PitZhu-2002 closed 4 months ago

PitZhu-2002 commented 7 months ago

Dear Developers: Deslib package is a really excellent framework which could be used by researchers and scientists and contributory to the community. But I have a few questions revelant to KNN in this framework when I complete my research project. Take "DESP(k = 7, random_state = 10).fit(X_dsel, y_dsel)" as an example: (1) Does the framework really find the 7 nearest neighbors in X_dsel for each query sample? (2) If I employ KNN classifier to select k nearest neighbors (i.e, X_knn, y_knn)in X_dsel of the query sample by myself of the framework, and then pass those k nearest neighbors in DES method realized by this framework (e.g., DESP(k = k).fit(X_knn, y_knn)). Compared to the traiditional method (i.e., (DESP(k = k).fit(X_dsel, y_dsel))), does those two writings find identical knn of the query sample ? Thank you, Best wishes!

Menelau commented 4 months ago

Hello @PitZhu-2002

Sorry for the late response. Here are the answers:

1) Yes, that is what it does.

2) At the moment, the framework does not allow passing a pre-computed set of neighbors and passing it for the method. The data passed to the fit method. If you want to pass a pre-computed set of neighbors to the method in order to change its behavior or speed up computations, you would need to change the source code for that. In this case, it would probably imply a modification in the predict method to receive the set of pre-computed nearest neighbors also as input and use them for the calculations instead of it computing directly in the method.