Date
Function
sklearn.tree:
Multi-select
Status
Not started
Status
URL
- Decision tree based models for classification and regression.
- Exporting
- Plotting
š Study Note: sklearn.tree
TheĀ sklearn.treeĀ module in Scikit-learn is primarily used for decision tree algorithms and associated utilities. Below is a detailed list of the available classes, functions, and attributes underĀ sklearn.tree:
The sklearn.tree contains three major model
1. Decision Tree Models | A decision tree classifier. | |
A decision tree regressor. | ||
2. Extra Tree Models | An extremely randomized tree classifier. | |
An extremely randomized tree regressor. |
Classes
ā£
1. Decision Tree Models
ā£
2. Extra Tree Models
ā£
Functions
ā£
Attributes
ā£
Modules for Integration
ā£
Quick Summary
Explanation of Key Parameters
export_graphvizĀ Parameters:clf: The trained decision tree model.out_file=None: Returns the DOT data as a string instead of saving it to a file.feature_names: Names of the features used in training the model.class_names: Names of the classes for classification.filled=True: Adds colors to the nodes for better readability.rounded=True: Makes the edges and corners of the nodes rounded.special_characters=True: Supports special characters (e.g., for feature names).- Graphviz Object:
graphviz.Source: Converts DOT data into a graph object that can be displayed or saved.
Visualization Output
- Color Nodes: Nodes are color-coded to represent purity (e.g., Gini or entropy values).
- Feature Names: Each split is annotated with the corresponding feature.
- Class Names: Leaf nodes show the predicted class.
Notes
- Graphviz Installation:
- You must have Graphviz installed on your system forĀ
graphviz.SourceĀ to work. - Install via package manager:
- Python Library Installation:
- Install the Python wrapper for Graphviz:
- Alternative:
- UseĀ
tree.plot_tree()Ā for a Matplotlib-based visualization:
Copy code
# On Ubuntu/Debian:
sudo apt-get install graphviz
# On macOS:
brew install graphviz
bash
Copy code
pip install graphviz
from sklearn.tree import plot_tree
plot_tree(clf, feature_names=iris.feature_names, class_names=iris.target_names, filled=True)
plt.show()