Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sklearn管道中估计量的变换结果_Python_Scikit Learn_Pipeline_Xgboost - Fatal编程技术网

Python sklearn管道中估计量的变换结果

Python sklearn管道中估计量的变换结果,python,scikit-learn,pipeline,xgboost,Python,Scikit Learn,Pipeline,Xgboost,我有一个sklearn管道,它由一个定制的转换器组成,后跟XGBClassifier。我想在转换器中添加的最后一步是另一个自定义转换器,用于转换XGBClassifier的结果 最后一个自定义转换器将预测的概率按等级排列(5个百分点) 问题在于sklearn管道要求所有步骤(但最后一步)都有一个fit and transform方法。我可以用另一种方法来解决这个问题,而不是扩展XGBclassifier并向其添加转换方法吗?从实现的源代码来看,用于拟合数据的估计器位于步骤的最后位置,管道的\u

我有一个sklearn管道,它由一个定制的转换器组成,后跟XGBClassifier。我想在转换器中添加的最后一步是另一个自定义转换器,用于转换XGBClassifier的结果

最后一个自定义转换器将预测的概率按等级排列(5个百分点)


问题在于sklearn管道要求所有步骤(但最后一步)都有一个fit and transform方法。我可以用另一种方法来解决这个问题,而不是扩展XGBclassifier并向其添加转换方法吗?

从实现的源代码来看,用于拟合数据的估计器位于步骤的最后位置,管道的
\u final\u estimator
属性调用管道步骤的最后位置

@property
def _final_estimator(self):
    estimator = self.steps[-1][1]
    return 'passthrough' if estimator is None else estimator
其中,
步骤
可能类似于

steps = [('scaler', StandardScaler(copy=True, with_mean=True, with_std=True)),
 ('svc',
  SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
      decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf',
      max_iter=-1, probability=False, random_state=None, shrinking=True,
      tol=0.001, verbose=False))]
在一个接一个地拟合所有变换之后,只需调用
\u final\u estimator
属性,即可获得要拟合到模型的估计器,有关详细信息,请参见第行

因此,考虑到
步骤
,我可以从它的最后位置检索一个
SVC

final_estimator = steps[-1][1]
final_estimator
>>> SVC(C=1.0, ..., verbose=False)
并将其与训练数据相匹配

final_estimator.fit(Xt, y)

其中
Xt
是转换后的训练数据(在拟合估计器之前),而
y
是训练目标。

从实现的源代码来看,用于拟合数据的估计器位于步骤的最后一个位置,管道的
\u final\u估计器
属性调用管道步骤的最后位置

@property
def _final_estimator(self):
    estimator = self.steps[-1][1]
    return 'passthrough' if estimator is None else estimator
其中,
步骤
可能类似于

steps = [('scaler', StandardScaler(copy=True, with_mean=True, with_std=True)),
 ('svc',
  SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
      decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf',
      max_iter=-1, probability=False, random_state=None, shrinking=True,
      tol=0.001, verbose=False))]
在一个接一个地拟合所有变换之后,只需调用
\u final\u estimator
属性,即可获得要拟合到模型的估计器,有关详细信息,请参见第行

因此,考虑到
步骤
,我可以从它的最后位置检索一个
SVC

final_estimator = steps[-1][1]
final_estimator
>>> SVC(C=1.0, ..., verbose=False)
并将其与训练数据相匹配

final_estimator.fit(Xt, y)
其中,
Xt
是转换后的训练数据(在拟合估计器之前),而
y
是训练目标