我使用该模型对一组数据进行了1000次迭代的分类器训练:
clf = GradientBoostingClassifier(n_estimators=1000, learning_rate=0.05, subsample=0.1, max_depth=3)
clf.fit(X, y, sample_weight=train_weight)现在,我想将迭代次数增加到2000年。所以我想:
clf.set_params(n_estimators=2000, warm_start=True)
clf.fit(X, y, sample_weight=train_weight)但我得到了以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-49cfdfd6c024> in <module>()
1 start = time.clock()
2 clf.set_params(n_estimators=2000, warm_start=True)
----> 3 clf.fit(X, y, sample_weight=train_weight)
4 ...
C:\Anaconda3\lib\site-packages\sklearn\ensemble\gradient_boosting.py in fit(self, X, y, sample_weight, monitor)
1002 self.estimators_.shape[0]))
1003 begin_at_stage = self.estimators_.shape[0]
-> 1004 y_pred = self._decision_function(X)
1005 self._resize_state()
1006
C:\Anaconda3\lib\site-packages\sklearn\ensemble\gradient_boosting.py in _decision_function(self, X)
1120 # not doing input validation.
1121 score = self._init_decision_function(X)
-> 1122 predict_stages(self.estimators_, X, self.learning_rate, score)
1123 return score
1124
sklearn/ensemble/_gradient_boosting.pyx in sklearn.ensemble._gradient_boosting.predict_stages (sklearn\ensemble\_gradient_boosting.c:2564)()
ValueError: ndarray is not C-contiguous我在这里做错什么了?
发布于 2016-03-02 23:28:17
您通常不能在fit调用之间修改sklearn分类器并期望它能够工作。估计器的数量实际上会影响模型内部对象的大小--因此它不仅仅是一些迭代(从编程的角度来看)。
发布于 2016-10-17 05:00:53
发布于 2016-10-18 16:07:45
在我看来,问题在于您没有将warm_start=True传递给构造函数。如果你这样做了:
clf = GradientBoostingClassifier(n_estimators=1000, learning_rate=0.05, subsample=0.1, max_depth=3, warm_start=True)您将能够使用以下方法来拟合其他估计器:
clf.set_params(n_estimators=2000)
clf.fit(X, y, sample_weight=train_weight)如果它不起作用,你应该试着更新你的学习版本。
https://stackoverflow.com/questions/35760256
复制相似问题