csinva / imodels

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

FIGSRegressor failed to calculate importance_data_tree #179

Closed jckkvs closed 1 year ago

jckkvs commented 1 year ago

The following code snippet results in an error.

from imodels import FIGSRegressor
from sklearn.datasets import make_regression
X,y = make_regression(n_features=10)
figs = FIGSRegressor()
figs.fit(X,y)

The error

C:\Users\user\Anaconda3\envs\py310\lib\site-packages\imodels\tree\figs.py:377: RuntimeWarning: invalid value encountered in divide
  importance_data_tree /= tree_samples

This error is caused by the following implementations: https://github.com/csinva/imodels/blob/59353613dc1f456ba243112d9e6b8f313180da18/imodels/tree/figs.py#L342 https://github.com/csinva/imodels/blob/59353613dc1f456ba243112d9e6b8f313180da18/imodels/tree/figs.py#L347

value_counts[0.0] and value_counts[1.0] are code assuming Classifier and do not work with Regressor.