Im working with count data and want to fit a poisson regression with a L1 norm. I have the following code which throws the error and is reproducable:
import numpy as np
import skglm
import sklearn
X = np.random.rand(100, 10)
y = np.random.poisson(lam=2.0, size=100) + 1 #If poisson == 1 at any point in throws error, so add 1.
# Split the data into training and test sets
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size=0.2, random_state=42)
# Create the Poisson regression model with L1 regularization
poisson_model = skglm.GeneralizedLinearEstimator(datafit=skglm.datafits.Poisson(), penalty=skglm.penalties.L1(alpha=1.0))
# Fit the model to the training data
#The error is thrown on this line.
poisson_model.fit(X_train, y_train)
# Predict on the test set
y_pred = poisson_model.predict(X_test)
# Evaluate the model
mse = sklearn.metrics.mean_squared_error(y_test, y_pred)
print(f'Mean Squared Error: {mse}')
The error I get running on skglm 0.3.1 (most recent version I think):
'Poisson' object has no attribute 'get_lipschitz'
.
This thread on sklearn says that it should be possible to perform a poisson regression with an L1 norm, but I can’t figure out what I’m doing wrong.
Any help is greatly appreciated, thank you!