parrt / dtreeviz

A python library for decision tree visualization and model interpretation.
MIT License
2.89k stars 332 forks source link

'function' object has no attribute 'model' #268

Open HarshKapadia opened 1 year ago

HarshKapadia commented 1 year ago

I am facing this issue while visualizing a decision tree using dtreeviz . I follow your demo of sklearn from READ.md. I am using vscode and download jupyter notebook as extension.

this is what I got after executing it

AttributeError Traceback (most recent call last) Cell In[37], line 1 ----> 1 viz_model = dtreeviz.model(tree_classifier, 2 X_train=dataset[features], y_train=dataset[target], 3 feature_names=features, 4 target_name=target, class_names=["perish", "survive"])

AttributeError: 'function' object has no attribute 'model'

parrt commented 1 year ago

Hmm...must be an old version of dtreeviz?

HarshKapadia commented 1 year ago

this is my package details

Name: dtreeviz Version: 2.0.0 Summary: A Python 3 library for sci-kit learn, XGBoost, LightGBM, Spark, and TensorFlow decision tree visualization Home-page: https://github.com/parrt/dtreeviz Author: Terence Parr, Tudor Lapusan, and Prince Grover Author-email: parrt@antlr.org License: MIT Location: c:\users\UserName\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages Requires: colour, graphviz, matplotlib, numpy, pandas, pytest, scikit-learn Required-by:

tlapusan commented 1 year ago

@HarshKapadia I suspect it's an import issue. Please double check there, because your code sees the dtreeviz as a function, as it was in the old version of the library.

Maybe this could help also : https://stackoverflow.com/questions/75346507/dtreeviz-nameerror

If you followed all the above suggestions and still no success, providing a collab notebook or some sharable code to reproduce the issue would help us :)

TesfamariamAbuhay commented 9 months ago

I am also having the same issue while trying to visualize a representative tree of xgboost classifier. AttributeError Traceback (most recent call last)

in ----> 1 viz_model = dtreeviz.model(best_model_O, 2 X_train=X_train_O, y_train_O=y_train_O, 3 feature_names=X_train_O.columns.tolist(), 4 target_name='Risk Level', 5 class_names=best_model_O.classes_) AttributeError: module 'dtreeviz' has no attribute 'model' I am using dtreeviz-2.2.2 @parrt and @tlapusan any solution?