Decision tree code
from sklearn.datasets import load_iris
import pydotplus
from IPython.display import Image
from sklearn import tree
#Training Model
iris=load_iris()
clf=tree.DecisionTreeClassifier()
clf=clf.fit(iris.data,iris.target)
#Drawing
dot_data=tree.export_graphviz(decision_tree=clf,
out_file=None,
rounded=True,
filled=True,
feature_names=iris.feature_names)
graph=pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())
Installation
Install pydotplus
pip install pydotplus
Running error: graphviz’s executables not found
Installing graphviz
pip install graphviz
Graphviz’s executables not found
After consulting the data, graphviz belongs to an independent software, which needs to be downloaded and installed on the official website
Website: http://www.graphviz.org/Download
Add environment variable
There are two methods, and the second one is recommended for personal test
Method 1: add the path of graphviz’s bin directory in environment variable.
Method 2: OS method
CMD
python
Enter Python environment
imoprt os
os.environ["PATH"]+= os.pathsep+"C:/Program Files/Graphviz/bin" # change to your path of Graphviz
Done!
Operation results
If it is used in jupyter notebook like me, you need to restart jupyter notebook
Read More:
- Graphviz Install Error: There is no layout engine support for “dot“
- TensorFlow Install Error: Could not load dynamic library ‘*****.dll‘; dlerror: ********.dll not found
- [Mac Pro M1] Python3.9 import cv2 Error: Reason: image not found
- [Solved] Numpy Load Error: DLL load failed while importing _multiarray_umath: Could not be found Module
- [Solved] DLL load failed while importing _sqlite3: the specified module could not be found.
- ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
- AttributeError: lower not found (NLP extracted tfidf features)
- [Solved] gyp verb `which` failed Error: not found: python2
- [Solved] HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/saved_model
- [Solved] librosa Install Error: ImportError: DLL load failed: Could Not Found
- [Solved] Pdfplumber Read PDF Sheet Error: AttributeError: function/symbol ‘ARC4_stream_init‘ not found in library
- Import win32API; importerror: DLL load failed: the specified program was not found
- import statsmodels.api as sm Error: ImportError: DLL load failed while importing _arpack: The specified program could not be found.
- [Solved] R Error: Python module tensorflow.keras was not found.
- Module not found error: no module named ‘filefolder’ appears when learning engineering knowledge
- [nltk_data] Error loading wordnet_ic: HTTP Error 404: Not Found
- Pycharm error: original error was: DLL load failed while importing _multiarray _Umath: the specified module could not be found
- Python error: urllib.error.HTTPError : http Error 404: not found
- MYSQL-python Install EnvironmentError: mysql_config not found
- Pyinstaller Error: INTEL MKL ERROR: The specified module could not be found. mkl_intel_thread.1.dll.Intel MKL FATAL ERROR: Cannot