scikit-learn: GLM doesn't have an offset option
Describe the workflow you want to enable
As described at #24155, GLM should also support the offset option.
Describe your proposed solution
For example
from sklearn.linear_model import PoissonRegressor
glm = PoissonRegressor(
alpha=0,
fit_intercept=False,
max_iter=300,
offset=A # offset option
)
glm.fit(X_train, y_train)
Describe alternatives you’ve considered, if relevant
No response
Additional context
No response
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 15 (11 by maintainers)
Hi all, are there any news on this feature? Do you think that there are any possibilities that it will be implemented in a near future? 😊
In the GLM literatur, offsets have a clear meaning. This is reflected by implementations of GLMs in R where
offsetcan be part of the model formula:statsmodels, Julia.
My main concern is that it does not fit in our API.
For reference, glum uses the 3rd approach, i.e. argument in fit and predict, see https://glum.readthedocs.io/en/latest/glm.html#glum.GeneralizedLinearRegressor.fit.
Hi, with @manudarmi and our team we are working on adding offsets to the GLMs.
We have a working implementation which passes the offset as a kwarg of the
fitmethod.It would look like this:
With
offsetbeing an array-like with the same shape assample_weight.The main problem is that whenever offsets are not known a priori (e.g. computed during a previous step in a pipeline), it would be impossible to pass them to the GLM without creating a custom wrapper.
For example:
A solution could be to track whether the GLM expects offsets or not as a constructor argument, and then expect them to be either in the first or last column of X. This would make the snippet above work properly, at the cost of being less explicit.
Would look like this:
If you could give me some feedback I could start working towards a PR in either direction 😄
I know about 2 use cases:
It’s usually not the intercept, but a certain (amount of) coefficient(s) that one wants to fix.