gpt4 book ai didi

python - 使用pipeline时为什么不改造X_test

转载 作者:行者123 更新时间:2023-12-01 06:29:26 25 4
gpt4 key购买 nike

我在一篇文章上看到https://towardsdatascience.com/multi-class-text-classification-with-sklearn-and-nltk-in-python-a-software-engineering-use-case-779d4a28ba5

   X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.25)

第 1 步:我们可以使用管道一次完成所有这些步骤,而不是一次执行一个步骤

      pipeline = Pipeline([('vect', tfidf),
('clf', RandomForestClassifier())])

第2步拟合我们的模型并将其保存在pickle中以供以后使用

      model = pipeline.fit(X_train, y_train)
prediction= model.predict(X_test)

通常情况下,如果我们手动进行

   X_train= tfidf.fit_transform(X_train)
X_test=tfidf.transform(X_test)
model=RandomForestClassifier()
model.fit(X_train,y_train)
prediction=model.predict(X_test)

我的问题是:如果我按照文章操作,并在步骤2中执行这些代码,我是否会错过这段代码

   X_test=tfidf.transform(X_test)

我没有看到作者变换X_test。他只是使用原来的X_test。作者的话属实吗?

之后

最佳答案

My question is: If I follow the article, and perform these codes in step2 , do I miss this code

不,作者是正确的。

在调用model.predict()时,作者使用的是Pipeline类函数predict()as you can see in the docs ...

Apply transforms to the data, and predict with the final estimator

因此,X_test 首先经过变换,然后用于预测目标变量。

关于python - 使用pipeline时为什么不改造X_test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59975984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com