Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] KernelExplainer returns TypeError for certain input #4270

Closed
Nanthini10 opened this issue Oct 6, 2021 · 0 comments · Fixed by #4272
Closed

[BUG] KernelExplainer returns TypeError for certain input #4270

Nanthini10 opened this issue Oct 6, 2021 · 0 comments · Fixed by #4272
Assignees
Labels
bug Something isn't working Cython / Python Cython or Python issue

Comments

@Nanthini10
Copy link
Contributor

Describe the bug
SHAP returns TypeError: X matrix must have at least a column this is likely because none of the features are deemed important enough, so a 0 column input is passed to LR.

Steps/Code to reproduce bug

from cuml.explainer import KernelExplainer
from cuml.datasets import make_regression
from cuml import Lasso
X, y = make_regression(n_samples=100, n_features=10)
clf = Lasso()
clf.fit(X,y)

exp = KernelExplainer(model=clf.predict, data=X, nsamples=10)
exp.shap_values(X)
Error
/opt/conda/envs/rapids/lib/python3.8/site-packages/sklearn/linear_model/_least_angle.py:615: ConvergenceWarning: Regressors in active set degenerate. Dropping a regressor, after 2 iterations, i.e. alpha=5.722e-07, with an active set of 2 regressors, and the smallest cholesky pivot element being 2.220e-16. Reduce max_iter or increase eps parameters.
  warnings.warn('Regressors in active set degenerate. '
/opt/conda/envs/rapids/lib/python3.8/site-packages/sklearn/linear_model/_least_angle.py:615: ConvergenceWarning: Regressors in active set degenerate. Dropping a regressor, after 3 iterations, i.e. alpha=2.861e-07, with an active set of 3 regressors, and the smallest cholesky pivot element being 2.220e-16. Reduce max_iter or increase eps parameters.
  warnings.warn('Regressors in active set degenerate. '
/opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py:409: UserWarning: Changing solver from 'eig' to 'svd' as eig solver does not support training data with 1 column currently.
  return func(*args, **kwargs)
/opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py:409: UserWarning: Changing solver from 'eig' to 'svd' as eig solver does not support training data with 1 column currently.
  return func(*args, **kwargs)
/opt/conda/envs/rapids/lib/python3.8/site-packages/sklearn/linear_model/_least_angle.py:642: ConvergenceWarning: Early stopping the lars path, as the residues are small and the current value of alpha is no longer well controlled. 4 iterations, alpha=4.860e-02, previous alpha=4.334e-02, with an active set of 5 regressors.
  warnings.warn('Early stopping the lars path, as the residues '
/opt/conda/envs/rapids/lib/python3.8/site-packages/sklearn/linear_model/_least_angle.py:615: ConvergenceWarning: Regressors in active set degenerate. Dropping a regressor, after 7 iterations, i.e. alpha=1.619e-07, with an active set of 7 regressors, and the smallest cholesky pivot element being 2.220e-16. Reduce max_iter or increase eps parameters.
  warnings.warn('Regressors in active set degenerate. '
/opt/conda/envs/rapids/lib/python3.8/site-packages/sklearn/linear_model/_least_angle.py:615: ConvergenceWarning: Regressors in active set degenerate. Dropping a regressor, after 7 iterations, i.e. alpha=1.245e-07, with an active set of 7 regressors, and the smallest cholesky pivot element being 2.220e-16. Reduce max_iter or increase eps parameters.
  warnings.warn('Regressors in active set degenerate. '

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-b6cdbd890780> in <module>
      8 
      9 exp = KernelExplainer(model=clf.predict, data=X, nsamples=10)
---> 10 exp.shap_values(X)

cuml/explainer/kernel_shap.pyx in cuml.explainer.kernel_shap.KernelExplainer.shap_values()

cuml/explainer/base.pyx in cuml.explainer.base.SHAPBase._explain()

cuml/explainer/kernel_shap.pyx in cuml.explainer.kernel_shap.KernelExplainer._explain_single_observation()

cuml/explainer/kernel_shap.pyx in cuml.explainer.kernel_shap._weighted_linear_regression()

/opt/conda/envs/rapids/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner_with_setters(*args, **kwargs)
    407                                 target_val=target_val)
    408 
--> 409                 return func(*args, **kwargs)
    410 
    411         @wraps(func)

cuml/linear_model/linear_regression.pyx in cuml.linear_model.linear_regression.LinearRegression.fit()

TypeError: X matrix must have at least a column

Expected behavior
It should either select at least one column or return a more descriptive error for the user. @dantegd What are you thoughts?

Environment details (please complete the following information):
docker 21.10 nightly

@Nanthini10 Nanthini10 added bug Something isn't working Cython / Python Cython or Python issue labels Oct 6, 2021
@Nanthini10 Nanthini10 self-assigned this Oct 6, 2021
rapids-bot bot pushed a commit that referenced this issue Oct 18, 2021
vimarsh6739 pushed a commit to vimarsh6739/cuml that referenced this issue Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cython / Python Cython or Python issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant