gpt4 book ai didi

python sklearn GradientBoostingClassifier热启动报错

转载 作者:行者123 更新时间:2023-11-28 17:29:16 25 4
gpt4 key购买 nike

我使用该模型在一组数据上训练了一个分类器,迭代次数为 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

我在这里做错了什么?

最佳答案

warm_start 被正确使用。实际上有一个错误阻止了它的工作。

同时的解决方法是将数组复制到 C 连续数组:

X_train = np.copy(X_train, order='C')
X_test = np.copy(X_test, order='C')

引用:discussionbug

关于python sklearn GradientBoostingClassifier热启动报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35760256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com