KElbowVisualizer wrapping functionality does not work with notebook rendering of estimator
vtphan opened this issue · 4 comments
Describe the bug
In Jupyter Notebook, this code produces this error:
AttributeError: 'KMeans' object has no attribute 'k'
To Reproduce
from sklearn.cluster import KMeans
from yellowbrick.cluster import KElbowVisualizer
visualizer = KElbowVisualizer(KMeans(), k=(2,12))
visualizer
Additional context
The use case above is just an example. The bug shows in other complex use cases.
@lwgray I was able to reproduce this error on:
Python: 3.10.2
Yellowbrick: develop branch
Dependencies:
matplotlib==3.5.2
scipy==1.8.1
scikit-learn==1.1.1
numpy==1.22.4
cycler==0.11.0
Taking a look at it now.
@vtphan @lwgray this appears to be related to the new scikit-learn print functionality that attempts to render Estimators using matplotlib with interactive dropdowns, e.g.
Because the last line of the cell is visualizer
the notebook is trying to render it as output and because the visualizer extends Estimator
it goes through the scikit-learn pretty drawing functionality.
@vtphan this bug does not affect the behavior of the visualizer; you can still fit and show the visual image, but I can see how it can be annoying, so it's something we'll want to try to deal with.
Turns out this is specifically a problem with KElbowVisualizer
-- PR fix coming.