Testing methods to reduce dimensionality with pipelines
Here we will see how different estimators composed of dimensionality reduction and a support vector machine perform.
Getting ready
Load the iris dataset and some dimensionality reduction libraries. This is a big step for this particular recipe:
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_iris from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline from sklearn.svm import SVC, LinearSVC from sklearn.decomposition import PCA, NMF, TruncatedSVD from sklearn.manifold import Isomap %matplotlib inline
How to do it...
- Instantiate a pipeline object with two main parts:
- An object to reduce dimensionality
- An estimator with a predict method
pipe = Pipeline([ ('reduce_dim', PCA()), ('classify', SVC()) ])
- Note in the following code that Isomap comes from the
manifold
module and that the non-negative matrix factorization (NMF) algorithm utilizes SVDs to break up a matrix into...