简体   繁体   English

重新适合决策树以添加层

[英]Re-fit a decision tree to add a layer

I am wondering if there is a way to re-use an existing DecisionTreeClassifier to add another layer. 我想知道是否有一种方法可以重复使用现有的DecisionTreeClassifier添加另一层。

My scenario is the following: 我的情况如下:

  • I have some data (data array X with corresponding labels y ) for classification 我有一些数据(带有相应标签y的数据数组X )用于分类
  • I train a DecisionTreeClassifier with max_depth=1 on my (X,y) data. 我在(X,y)数据上训练了一个max_depth=1DecisionTreeClassifier
  • While I am not satisfied with my classifier: 虽然我对分类器不满意:
    • Re-use the same classifier with the same data, to add leaves at the bottom of my tree, therefore increasing the depth by 1 (It's important that I keep the same tree, I am just adding a layer of leaves at the bottom, I am not retraining a new DecisionTree with max_depth=n+1 ) 重复使用具有相同数据的相同分类器,在树的底部添加叶子,因此将深度增加1(重要的是我要保留同一棵树,我只是在底部添加了一层叶子,不使用max_depth=n+1重新训练新的DecisionTree)

Is there a way to do this with scikit-learn? scikit-learn有办法做到这一点吗? Or with other classifiers, like a neural network, can you train your neural network with, say, 10 epochs, then if it is not accurate enough, re-train it with another 10 epochs, and so on? 或使用其他分类器(例如神经网络),您是否可以用10个历元来训练神经网络,如果它不够准确,请再用10个历元来进行训练,依此类推?

Short answer : 简短答案:

No , you can't. ,你不能。

Long answer : 长答案:

A DecisionTreeClassifier is not meant to be fitted again. DecisionTreeClassifier不能再次拟合。 As you can see in the source code tree.py at line 350, the internal tree is built using some class inheriting from TreeBuilder. 正如您在第350行的源代码tree.py中看到的那样,内部树是使用继承自TreeBuilder的某些类构建的。 This class is from the cpython file _tree.py . 此类来自cpython文件_tree.py You can still try to tweak this class by copy / pasting chunks of its code ... I wouldn't recommend it because it is pain in the neck and it is not likely to work at all. 您仍然可以尝试通过复制/粘贴其代码块来调整该类……我不建议您这样做,因为它会给您带来痛苦,并且根本无法正常工作。

Hope you will find (or found) another solution and will share it with us :) 希望您能找到(或找到)另一种解决方案并与我们分享:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM