csinva / imodels

Interpretable ML package 🔍 for concise, transparent, and accurate predictive modeling (sklearn-compatible).
https://csinva.io/imodels
MIT License
1.36k stars 121 forks source link

SlimRegressor error #25

Closed ukamath closed 3 years ago

ukamath commented 3 years ago

When I run SlimRegressor on a regression data from imodels import SLIMRegressor model = SLIMRegressor() for lambda_reg in [0, 1e-2, 5e-2, 1e-1, 1, 2]: model.fit(X_train, y_train, lambda_reg) mse = np.mean(np.square(y_train - model.predict(X_train))) print(f'lambda: {lambdareg}\tmse: {mse: 0.2f}\tweights: {model.model.coef}')

I get

SolverError: Either candidate conic solvers (['GLPK_MI']) do not support the cones output by the problem (SOC, NonNeg), or there are not enough constraints in the problem.

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)

in 2 model = SLIMRegressor() 3 for lambda_reg in [0, 1e-2, 5e-2, 1e-1, 1, 2]: ----> 4 model.fit(X_train, y_train, lambda_reg) 5 mse = np.mean(np.square(y_train - model.predict(X_train))) 6 print(f'lambda: {lambda_reg}\tmse: {mse: 0.2f}\tweights: {model.model.coef_}') ~/opt/anaconda3/lib/python3.7/site-packages/imodels/algebraic/slim.py in fit(self, X, y, lambda_reg, sample_weight) 58 except: 59 m = Lasso(alpha=lambda_reg) ---> 60 m.fit(X, y, sample_weight=sample_weight) 61 self.model.coef_ = np.round(m.coef_).astype(np.int) 62 self.model.intercept_ = m.intercept_ TypeError: fit() got an unexpected keyword argument 'sample_weight'
csinva commented 3 years ago

Thanks for your interest and pointing this out!

The issue here is that your scikit-learn version is < 0.23. To fix this, you'll have to upgrade it to 0.23 or higher. We'll add this to the requirements!