首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在运行期间计算python中GradientBoostingClassifier的损失

在运行期间计算python中GradientBoostingClassifier的损失
EN

Stack Overflow用户
提问于 2015-05-10 04:53:19
回答 2查看 649关注 0票数 0

我有以下用于创建和训练sklearn.ensemble.GradientBoostingClassifier的代码

代码语言:javascript
复制
class myMonitor:
    def __call__(self, i, estimator, locals):
        proba = estimator.predict_proba(Xp2)
        myloss = calculateMyLoss(proba, yp2) # calculateMyLoss is defined 
                                             # further on
        print("Calculated MYLOSS: ",myloss)
        return False

... #some more code

model = GradientBoostingClassifier(verbose=2, learning_rate = learningRate, n_estimators=numberOfIterations, max_depth=maxDepth, subsample = theSubsample, min_samples_leaf = minLeafSamples, max_features=maxFeatures)
model.fit(Xp1, yIntegersp1, monitor = myMonitor())

然而,当我运行这段代码时,我得到了错误:

代码语言:javascript
复制
    model.fit(Xp1, yIntegersp1, monitor = myMonitor())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 980, in fit
    begin_at_stage, monitor)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 1058, in _fit_stages
    early_stopping = monitor(i, self, locals())
  File "OTTOSolverGBM.py", line 44, in __call__
    proba = estimator.predict_proba(Xp2)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 1376, in predict_proba
    score = self.decision_function(X)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 1102, in decision_function
    score = self._decision_function(X)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/ensemble/gradient_boosting.py", line 1082, in _decision_function
    predict_stages(self.estimators_, X, self.learning_rate, score)
  File "sklearn/ensemble/_gradient_boosting.pyx", line 115, in sklearn.ensemble._gradient_boosting.predict_stages (sklearn/ensemble/_gradient_boosting.c:2502)
AttributeError: 'NoneType' object has no attribute 'tree_'

为什么我不能使用相同的估计器(不是None,我检查过了)来计算运行期间的类概率?有没有办法实现我想要的(例如,在拟合过程的每一次迭代中检查模型的验证数据)?

EN

回答 2

Stack Overflow用户

发布于 2015-05-11 20:07:00

您的estimatorself。试一试

代码语言:javascript
复制
def __call__(self, i, locals)
    proba = self.predict_proba(Xp2)
票数 1
EN

Stack Overflow用户

发布于 2015-05-12 06:56:22

你也许可以做一些类似于this example on forests的基于partial_fit的事情。要在培训后进行分析,请查看this example on gradient boosting.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30144901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档