【问题标题】:How to use my own classifier in ensemble python如何在 ensemble python 中使用我自己的分类器
【发布时间】:2016-11-23 06:41:47
【问题描述】:

主要目的是在python的集成中添加像CNN这样的深度学习分类方法。
以下代码工作正常:

   clf1=CNN()   
   eclf1=VotingClassifier(estimators=[('lr', clf1)], voting='soft')
   eclf1=eclf1.fit(XTrain,YTrain)

但是,错误:

'NoneType' object has no attribute 'predict_proba' 

一旦运行eclf1=eclf1.predict(XTest)就会出现。

以防万一,CNN 由用于训练的_fit_ 函数和以下函数组成:

def predict_proba(self,XTest):    
    #prediction=np.mean(np.argmax(teY, axis=1) == predict(teX))
    teX=XTest.reshape(len(XTest),3,112,112)
    p=predict(teX) 
    i = np.zeros((p.shape[0],p.max()+1))
    for x,y in enumerate(p):
        i[x,y] = 1 
    return i  

【问题讨论】:

    标签: python classification ensemble-learning sklearn-pandas


    【解决方案1】:

    你能详细说明你做了什么以及你遇到了什么错误吗?

    仅根据您的问题,我可以假设您尝试在 eclf1=eclf1.predict(XTest) 行之后调用“predic_proba”。当然,这会引发错误,因为eclf1.predict(XTest) 返回一个没有 predict() 方法的数组。 尝试将其更改为:

    pred_results=eclf1.predict(XTest)
    pred_result_probs = eclf1.predict_proba(XTest)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-31
      • 1970-01-01
      • 2016-09-06
      • 2012-02-07
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2010-09-10
      相关资源
      最近更新 更多