简体   繁体   English

如何手动 select 决策树的特征

[英]How to manually select the features of the decision tree

I need to be able to change the features (with the machine learning meaning) that are used to build the decision tree.我需要能够更改用于构建决策树的特征(具有机器学习含义)。 Given the example of the Iris Dataset, I want to be able to select the Sepallength as the feature used in the root node and the Petallength as a feature used in the nodes of the first level, and so on.给定 Iris 数据集的示例,我希望能够 select 将 Sepallength 作为根节点中使用的特征,Petallength 作为第一级节点中使用的特征,依此类推。

I want to be clear, my aim is not to change the minimum sample split and the random state of the decision tree.我想明确一点,我的目的不是改变决策树的最小样本拆分和随机 state。 But rather to select the features - the characteristics of the elements that are classified - and put them in some nodes of the decision tree.而是将 select 的特征——被分类的元素的特征——放在决策树的一些节点中。

The code should then be able to find the best threshold - range for each node - to generate the best split.然后代码应该能够找到最佳阈值 - 每个节点的范围 - 以生成最佳分割。

Here some general code about the tree generation.这里有一些关于树生成的通用代码。

from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris

clf = DecisionTreeClassifier(random_state=0)

iris = load_iris()

clf.fit(iris.data,iris.target)

Does any of you have ever done this?你们中有人做过吗?

Does any of you have ever done this?你们中有人做过吗?

No, you are probably the first one!不,你可能是第一个!

Haha, but you can select it in several ways, you can also find it in the offical documentation: https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html哈哈,不过你可以通过几种方式select,你也可以在官方文档中找到: https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.ZAD2536EZ70A8C79886

# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2]  # we only take the first two features.
y = iris.target

then you are doing: clf.fit(X, y)那么你正在做: clf.fit(X, y)

Ohter ways to do it are explained here: Selecting multiple columns in a pandas dataframe此处解释了其他方法: Selecting multiple columns in a pandas dataframe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何寻找随机森林树/决策树的特征? - How can look for the features of random forest tree/decision treee? 如何将混合(分类和数字)特征传递给 sklearn 中的决策树回归器? - how to pass mixed (categorical and numeric) features to Decision Tree Regressor in sklearn? 如何为决策树的连续特征选择拆分变量 - How to choose a split variables for continous features for decision tree 使用 pyplot 手动绘制决策树 - Plotting a decision tree manually with pyplot 如何从决策树中对功能进行取消编码以查看重要功能? - How may I un-encode the features from a decision tree to see the important features? Python sklearn决策树分类器具有多个功能? - Python sklearn decision tree classifier with multiple features? 确定为什么特征在决策树模型中很重要 - Determine WHY Features Are Important in Decision Tree Models 在决策树分类器中使用OneHotEncoder进行分类功能 - Using OneHotEncoder for categorical features in decision tree classifier 通过将2个要素捆绑在一起来“帮助”决策树 - “help” decision tree by tying 2 features together 在2D图上绘制具有3个特征的分类决策树的决策面 - Plot the decision surface of a classification decision tree with 3 features on a 2D plot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM