Building machine learning pipelines

The scikit-learn library has provisions to build machine learning pipelines. We just need to specify the functions, and it will build a composed object that makes the data go through the whole pipeline. This pipeline can include functions, such as preprocessing, feature selection, supervised learning, unsupervised learning, and so on. In this recipe, we will be building a pipeline to take the input feature vector, select the top k features, and then classify them using a random forest classifier.

How to do it…

  1. Create a new Python file, and import the following packages:
    from sklearn.datasets import samples_generator from sklearn.ensemble import RandomForestClassifier from sklearn.feature_selection import SelectKBest, ...

Get Python Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.