Pipeline可以将许多算法模型串联起来,比如将特征提取、归一化、分类组织在一起形成一个典型的机器学习问题工作流

Pipeline对象接收元组构成的列表作为输入,每个元组第一个值作为变量名,元组第二个元素是sklearn中的transformer或Estimator。管道中间每一步由sklearn中的transformer构成,最后一步是一个Estimator

from sklearn.preprocessing import StandardScaler # 用于进行数据标准化
from sklearn.decomposition import PCA # 用于进行特征降维
from sklearn.linear_model import LogisticRegression # 用于模型预测
from sklearn.pipeline import Pipeline
pipe_lr = Pipeline([('scl', StandardScaler()),
                    ('pca', PCA(n_components=2)),
                    ('clf', LogisticRegression(random_state=1))])
pipe_lr.fit(X_train, y_train)
print('Test Accuracy: %.3f' % pipe_lr.score(X_test, y_test))
y_pred = pipe_lr.predict(X_test)

 

相关文章:

  • 2021-07-07
  • 2021-12-06
  • 2021-05-19
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-01-21
猜你喜欢
  • 2021-12-14
  • 2022-12-23
  • 2021-04-03
  • 2021-10-08
  • 2021-12-10
  • 2021-12-10
  • 2021-07-26
相关资源
相似解决方案