Skip to content

Commit

Permalink
update import for newer sklearn compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
csinva committed May 22, 2024
1 parent 9443821 commit d443361
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions imodels/util/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd
import numpy as np
from sklearn.utils import indices_to_mask
from sklearn.utils._mask import indices_to_mask
from sklearn.linear_model import Lasso, LogisticRegression
from sklearn.linear_model._coordinate_descent import _alpha_grid
from sklearn.model_selection import cross_val_score
Expand Down Expand Up @@ -92,7 +92,8 @@ def score_linear(X, y, rules: List[str],
raise ValueError("Invalid alpha and max_rules passed")

if prediction_task == 'regression':
lin_model = Lasso(alpha=final_alpha, random_state=random_state, max_iter=2000)
lin_model = Lasso(alpha=final_alpha,
random_state=random_state, max_iter=2000)
else:
lin_model = LogisticRegression(
penalty=penalty, C=(1 / final_alpha), solver='liblinear',
Expand All @@ -110,7 +111,7 @@ def score_linear(X, y, rules: List[str],
if abs(w) > coef_zero_threshold:
nonzero_rules.append(Rule(r, args=[w], support=s))
coefs.append(w)

return nonzero_rules, coefs, lin_model.intercept_


Expand Down Expand Up @@ -139,7 +140,7 @@ def get_best_alpha_under_max_rules(X, y, rules: List[str],
m = LogisticRegression(
penalty=penalty, C=(1 / alpha), solver='liblinear', random_state=random_state)
cv_scoring = 'accuracy'

m.fit(X, y)
rule_coefs = m.coef_.flatten()
rule_count = np.sum(np.abs(rule_coefs) > coef_zero_threshold)
Expand All @@ -156,5 +157,5 @@ def get_best_alpha_under_max_rules(X, y, rules: List[str],
final_alpha = alphas[np.argmax(alpha_scores)]
else:
final_alpha = alphas[i - 1]

return final_alpha
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setuptools.setup(
name="imodels",
version="1.4.3",
version="1.4.4",
author="Chandan Singh, Keyan Nasseri, Matthew Epland, Yan Shuo Tan, Omer Ronen, Tiffany Tang, Abhineet Agarwal, Theo Saarinen, Bin Yu, and others",
author_email="chandan_singh@berkeley.edu",
description="Implementations of various interpretable models",
Expand Down

0 comments on commit d443361

Please sign in to comment.