Using python generators in scikit-learn [closed]

拟墨画扇 提交于 2019-12-08 11:50:07

问题


I was wondering whether and how it is possible to use a python generator as data input to scikit-learn classifier's .fit() functions? Due to huge amounts of data, this seems to make sense to me.

In particular I am about to implement a random forest approach.

Regards K


回答1:


The answer is "no". To do out of core learning with random forests, you should

  1. Split your data into reasonably-sized batches (restricted by the amount of RAM you have; bigger is better);
  2. train separate random forests;
  3. append all the underlying trees together in the estimators_ member of one of the trees (untested):

    for i in xrange(1, len(forests)):
        forests[0].estimators_.extend(forests[i].estimators_)`
    

(Yes, this is hacky, but no solution to this problem has been found yet. Note that with very large datasets, it might pay to just sample a number training examples that fits in the RAM of a big machine instead of training on all of it. Another option is to switch to linear models with SGD, those implement a partial_fit method, but obviously they're limited in the kind of functions they can learn.)




回答2:


The short answer is "No, you can't". Classical Random Forest classifier is not an incremental or online classifier, so you can't discard training data while learning, and have to provide all the dataset at once.

Due to popularity of RF in machine learning (not least because of the good prediction results for some interesting cases), there are some attempts to implement online variation of Random Forest, but to my knowledge those are not yet implemented in any python ML package.

See Amir Saffari's page for such an approach (not Python).



来源:https://stackoverflow.com/questions/20952418/using-python-generators-in-scikit-learn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!