Having trouble to display html output in data bricks python

640 Views Asked by At

There are similar question, but nothing solve my problem. One thing I think that the last line of my code doesn't work in data bricks (where I am working). I am displaying part of the code which you actually can't reproduce, but it's probably small issue that might be solved without reproducing code. But if it's needed, I will update that.

Another thing I got that I can probably use

displayHTML("""<p>https://www.medium.com" </p>""")

But I couldn't figure out how to get the the link. The part of the code is below (I fit a classification model) and want to use lime package to interpret.

!pip install lime
import lime
from lime import lime_tabular

explainer = lime_tabular.LimeTabularExplainer(
    training_data=np.array(X_train),
    feature_names=X_train.columns,
    class_names=['Fail', 'No_Fail'],
    mode='classification'
)
exp = explainer.explain_instance(
    data_row=X_test.iloc[1], 
    predict_fn=lgbm_class.predict_proba
)
exp.show_in_notebook(show_table=True)

What can I try next?

1

There are 1 best solutions below

0
On

Call to explainer.explain_instance returns an instance of the Explainer class, and this instance has the as_html function, so following theoretically should work:

exp = explainer.explain_instance(
    data_row=X_test.iloc[1], 
    predict_fn=lgbm_class.predict_proba
)
displayHTML(exp.as_html())