【问题标题】:Is it the same to use 1) StandardScaler & Classifier vs 2) Pipeline(Scalar, Classifier)?使用 1) StandardScaler & Classifier vs 2) Pipeline(Scalar, Classifier) 是否相同?
【发布时间】:2015-07-06 10:18:23
【问题描述】:

运行标准缩放器然后运行分类器会得到与使用管道相同的结果吗?

您好,我有一个分类问题,并尝试使用 scikit learn 的 StandardScaler() 来缩放 X 变量。我看到这样做的两种选择,理论上它们是否应该产生相同的结果?因为当我使用选项 (1) 时,我在测试数据集上获得了更好的精度分数。

(1)

scalar = StandardScaler()
xtrain_ = scalar.fit_transform(xtrain)
RFC = RandomForestClassifier(n_estimators=100)
RFC.fit(xtrain. ytrain)

xtest_ = scalar.transform(xtest)
score = cross_val_score(RFC, xtest_, ytest,cv=10, scoring ='precision')

(2)

RFCs = Pipeline([("scale", StandardScaler()), ("rf", RandomForestClassifier(n_estimators=100))])
RFCs.fit(xtrain, ytrain)
scores = cross_val_score(RFCs, xytest, ytest, cv=10, scoring='precision')

【问题讨论】:

    标签: python machine-learning random-forest


    【解决方案1】:

    您的选项号 2 使用的数据集 (xytest) 与您的版本号 (1) 使用的数据集 (xtest) 不同。此外,您的交叉验证应该包括训练,而不仅仅是预测。

    除此之外它们应该是相同的,而我建议你使用管道。

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 2015-07-12
      • 2011-01-17
      • 2019-02-05
      • 2012-03-22
      • 2018-02-07
      • 2019-08-11
      • 2016-08-12
      • 2020-07-13
      相关资源
      最近更新 更多