by zeec123 · 8y ago · 0 comments
There is so much wrong with the api design of sklearn (how can one think "predict_proba" is a good function name?). I can understand this, since most of it was probably written by PhD students without the time and expertise to come up with a proper api; many of them without a CS background. Compare this to e.g. the API of google/guava.
For example https://www.reddit.com/r/statistics/comments/8de54s/is_r_bet...
Case in point, sklearn doesn't have a bootstrap crossvalidator despite the bootstrap being one of the most
important statistical tools of the last two decades. In fact, they used to, but it was removed.
Weird right?
...
> We don't remove the sklearn.cross_validation.Bootstrap class because few people are using it,
> but because too many people are using something that is non-standard (I made it up) and very very
> likely not what they expect if they just read its name.
> At best it is causing confusion when our users read the docstring and/or its source code.
> At worse it causes silent modeling errors in our users code base.
...
Oh man, I thought of another great example. I bet you had no idea that
sklearn.linear_model.LogisticRegression is L2 penalized by default.
"But if that's the case, why didn't they make this explicit by calling it RidgeClassifier instead?"
Maybe because sklearn has a Ridge object already, but it exclusively performs regression?
Who knows (also... why L2 instead of L1? Yeesh). Anyway, if you want to just do unpenalized
logistic regression, you have to set the C argument to an arbitrarily high value,
which can cause problems. Is this discussed in the documentation?
Nope, not at all. Just on stackoverflow and github.
Is this opaque and unnecessarily convoluted for such a basic and crucial technique? Yup.
Or the following: https://www.reddit.com/r/haskell/comments/7brsuu/machine_lea...4 years ago they removed a misleading class - and even at the time the documentation was clear about what it was doing. I'm not sure how this reveals some huge flaw about scikit-learn. At best it shows that the contributors can realize their mistakes and solve them, without even needing people to point it out? That's great!
Also pointing to a bad implementation 4 years ago, for a project which has since then had way more funding for engineering time, and who's use has exploded, seems a bit misleading.
Have you ever tried looked at the pipeline cross validation, where you have to pass a dict of parameters to the function with underscore prefixes for each stage in the pipeline? Do this and you never call the API design amazing again.
There are examples for other bad design choices as well.
You are right, there is no alternative at the moment. Maybe julia lang will do better job, we will see.
Of the top 4 contributors to scikit-learn, 3 have computer science graduate degrees and 1 has a degree in physics, so I'm not sure that the lack of a "CS background" is the root cause of the majority of the problems with the codebase (perceived or actual).
It may more be related to the nature of academic code in general, since most of it is supposed to be more proof-of-concept rather than general use worthy (e.g., why Google's original code was refactored by Jeff Dean).
Granted I still use R for ML stuff, and I concede that silently regularizing regressions, and only being able to avoid doing so by hacking the penalty parameter, is terrifying.
Despite that, it does have some implementations that made it stick out for me across all other languages, such as the fit / transform / predict API spread across the library, and the useage of joblib as back-end for speedup - this allows their models to be easily scaleable on clusters with the use of Dask.
I still have confidence that their most used functions (e.g. RandomForest) and models are still correctly implemented and provide great value in that regard.
I'm not sure if the backends in use actually allow for a non-regularized use. I would assume so, but does someone know?