4 ms·
The syntax and usability of from sklearnex import patch_sklearn # The names match scikit-learn estimators patch_sklearn("SVC") seems quite clunky.
by evanb 5y ago
The syntax and usability of
from sklearnex import patch_sklearn
# The names match scikit-learn estimators
patch_sklearn("SVC")
seems quite clunky. I'd have preferred a syntax like
from sklearnex import SVC
Then, maintenance would be substantially easier. If sklearnex had import-level compatibility with sklearn it'd be as simple as some simple replacements,
import sklearn --> import sklearnex as sklearn
from sklearn.cluster import KMeans --> from sklearnex.cluster import KMeans
which seems much easier / clearer.
- sdenton4 5y agoI really really loathe import magics. You end up with situations where dependencies change global behavior without a way to track down where the change is actually coming from.
- sillysaurusx 5y agoImport magic ends up causing all kinds of problems. There's no way to tell it "I just want to import your classes; I don't want you to patch!" without literally patching the library. In general, I'm a fan of "let me call the initializer myself, at program startup." It's especially important when you want reversibility, i.e. teardown in addition to initialization, which pops up all the time for unit tests.
- dangerbird2 5y agoAlso networking/web apps with lifecycle hooks, where careless import-time logic can break the setup procedures. To quote zen of python, "explicit is better than implicit"
- napetrov 5y agopatching is just one of options to enable optimizations - You also can do already sklearnex import SVC There are other ways how you can enable this https://intel.github.io/scikit-learn-intelex/what-is-patching.html https://intel.github.io/scikit-learn-intelex/what-is-patchin...