You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to rely on the base class LinearModel to identify linear models, but I found out that SGDRegressor (nor any of its sub classes) is not inheriting this class. However, SGDClassifier is (through LinearClassifierMixin).
Is there any reason for BaseSGDRegressor to not inherit LinearModel? Is it because it overloads all of LinearModel's methods?
Steps/Code to Reproduce
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
issubclass(SGDRegressor, LinearModel)
Expected Results
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
issubclass(SGDRegressor, LinearModel)
True
Actual Results
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
Is there any reason for BaseSGDRegressor to not inherit LinearModel? Is it because it overloads all of LinearModel's methods?
Yes, I believe it was historically written independently of other linear models. Maybe subclassing from the base class could allow for some code reuse, although I have not checked.
Note that the LinearModel is not meant to be part of the public API and was not intended for model discovery but only for code reuse/factorization. AFAIK scikit-learn does not expose any public API to inspect which models can be considered linear models.
If subclassing can help remove redundant code, then I am not opposed to a PR. But if subclassing does not help reduce code complexity, I see little benefit to doing so. Extra indirections introduced by inheritance make it harder to navigate the code base and (slightly) hurt code readability as a result.
Describe the bug
I wanted to rely on the base class LinearModel to identify linear models, but I found out that SGDRegressor (nor any of its sub classes) is not inheriting this class. However, SGDClassifier is (through LinearClassifierMixin).
Is there any reason for BaseSGDRegressor to not inherit LinearModel? Is it because it overloads all of LinearModel's methods?
Steps/Code to Reproduce
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
issubclass(SGDRegressor, LinearModel)
Expected Results
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
issubclass(SGDRegressor, LinearModel)
True
Actual Results
from sklearn.linear_model import SGDRegressor
from sklearn.linear_model._base import LinearModel
issubclass(SGDRegressor, LinearModel)
False
Versions
The text was updated successfully, but these errors were encountered: