您的位置:首页 > 其它

pipeline 对部分特征进行处理

2017-08-17 14:24 106 查看
http://scikit-learn.org/stable/auto_examples/preprocessing/plot_function_transformer.html#sphx-glr-auto-examples-preprocessing-plot-function-transformer-py

利用下面的方法实现, 先对某一些进行选择,然后利用featureUnin 进行合并,重新变成整个特征集 。

def all_but_first_column(X):
return X[:, 1:]

def drop_first_component(X, y):
"""
Create a pipeline with PCA and the column selector and use it to
transform the dataset.
"""
pipeline = make_pipeline(
PCA(), FunctionTransformer(all_but_first_column),  # 先对整个特征集做pca,然后再滤掉第一列。即0列。
)
X_train, X_test, y_train, y_test = train_test_split(X, y)
pipeline.fit(X_train, y_train)
return pipeline.transform(X_test), y_test
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐