如何通过tree.plot_tree设置树视图中的列名?

时间:2019-06-08 04:05:53

标签: python pandas machine-learning scikit-learn decision-tree

我正在尝试通过sklearn lib树绘制一棵树,但是问题是列索引写在图片中。

public buildForm() { this.editForm = this.form.group({ username: [this.username, [Validators.required, Validators.minLength(this.minLength), CustomValidators.validateCharacters], AlreadyTakenValidator.checkUsername(this.registrationService)], email: [this.email, [Validators.required, Validators.email, CustomValidators.validateCharacters], AlreadyTakenValidator.checkEmail(this.registrationService)], oldPassword: ['', [Validators.required]], newPassword: ['', [Validators.required]], newPasswordConf: ['', [Validators.required]], firstname: [this.firstname, [Validators.required, NoWhitespaceValidator()]], lastname: [this.lastname, [Validators.required, NoWhitespaceValidator()]], country: ['', [Validators.required]], dateOfBirth: ['', [Validators.required]], gender: ['', [Validators.required]], } , { validator: MustMatch('newPassword', 'newPasswordConf') }) }

enter image description here

1 个答案:

答案 0 :(得分:2)

使用feature_names and class_names parameters

from sklearn.datasets import load_iris
from sklearn import tree

iris = load_iris()
clf = tree.DecisionTreeClassifier(random_state=0).fit(iris.data, iris.target)


tree.plot_tree(clf, feature_names=iris.feature_names, class_names=iris.target_names)

enter image description here