使用StackingClassifier + Pipeline时CalibratedClassifierCV的拟合函数出现问题

时间:2019-09-22 18:49:19

标签: python scikit-learn pipeline calibration

我有一个管道对象列表作为分类器列表。然后,我在StackingClassifier中使用这些分类器。现在,我想应用CalibratedClassifierCV方法。

  

注意:在拟合函数中,传递主数据的索引,而不是2D特征向量。

def input(index_list):
  return main_data[index_list]# return 2d feature vectors

input_function = FunctionTransformer(func= input, validate=False, accept_sparse=False)
clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)
meta_clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)

clf1 = Pipeline(steps=[('function_name', input_function), ('clf',clf)])
clf2 = Pipeline(steps=[('function_name', input_function), ('clf',clf)])

X= np.array([1,20,40, 60])# For example
y= np.array([0, 0, 1, 1])# For example

clf1.fit(X,y)# here, I am passing only the indices of the `main data array` and `input` function will return the actual 2d data through the pipeline.
clf2.fit(X,y)

stack_clf = StackingClassifier(classifiers=[clf1, clf2], meta_classifier=meta_clf,use_probas=True, average_probas=False)
    sclfdict_parc_dt.fit(X, y)
  

到目前为止,stackingclassifier或管道的fit函数运行良好。

     

现在,我要在CalibratedClassifierCV上应用StackingClassifier

sig_clf = CalibratedClassifierCV(stack_clf , method="sigmoid", cv="prefit")
sig_clf.fit(X_test, y_test) # Get errors from the line
  

错误:ValueError:预期的2D数组,而是1D数组:   数组= [2 4 31 33 47 100 117 160 173 375 379 387 401 405 405 426 430 431    455]。如果数据具有单个功能,则使用array.reshape(-1,1)来重塑数据;如果包含单个样本,则使用array.reshape(1,-1)来重塑数据。

有人可以帮忙吗?

0 个答案:

没有答案